Skip to content

Commit 75729ae

Browse files
authored
Merge pull request #195 from davellanedam/development
Development
2 parents d9d6e19 + d6db863 commit 75729ae

File tree

10 files changed

+1598
-1451
lines changed

10 files changed

+1598
-1451
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dist: xenial
22
language: node_js
33
node_js:
4-
- '8'
4+
- '10'
55
cache:
66
npm: true
77
services:

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## v8.0.1 (March 16, 2020)
2+
3+
- NPM updated
4+
5+
## v8.0.0 (March 16, 2020)
6+
7+
- This major version requires node 10+ because new bcrypt lib
8+
- Use of bcrypt lib
9+
- New test for users
10+
- NPM updated
11+
112
## v7.1.2 (January 12, 2020)
213

314
- Added cross-env to solve windows envionment issues

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Feel free to send me a tweet <https://twitter.com/davellanedam>, share this with
5757

5858
## Requirements
5959

60-
- Node.js **8+**
60+
- Node.js **10+**
6161
- MongoDB **3.6+**
6262
- Redis **5.0+**
6363

app/middleware/auth.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const crypto = require('crypto')
2-
const algorithm = 'aes-256-ecb'
2+
33
const secret = process.env.JWT_SECRET
4+
const algorithm = 'aes-192-cbc'
5+
// Key length is dependent on the algorithm. In this case for aes192, it is
6+
// 24 bytes (192 bits).
7+
const key = crypto.scryptSync(secret, 'salt', 24)
8+
const iv = Buffer.alloc(16, 0) // Initialization crypto vector
49

510
module.exports = {
611
/**
@@ -27,23 +32,28 @@ module.exports = {
2732
* Encrypts text
2833
* @param {string} text - text to encrypt
2934
*/
35+
3036
encrypt(text) {
31-
const cipher = crypto.createCipher(algorithm, secret)
32-
let crypted = cipher.update(text, 'utf8', 'hex')
33-
crypted += cipher.final('hex')
34-
return crypted
37+
const cipher = crypto.createCipheriv(algorithm, key, iv)
38+
39+
let encrypted = cipher.update(text, 'utf8', 'hex')
40+
encrypted += cipher.final('hex')
41+
42+
return encrypted
3543
},
3644

3745
/**
3846
* Decrypts text
3947
* @param {string} text - text to decrypt
4048
*/
49+
4150
decrypt(text) {
42-
const decipher = crypto.createDecipher(algorithm, secret)
51+
const decipher = crypto.createDecipheriv(algorithm, key, iv)
52+
4353
try {
44-
let dec = decipher.update(text, 'hex', 'utf8')
45-
dec += decipher.final('utf8')
46-
return dec
54+
let decrypted = decipher.update(text, 'hex', 'utf8')
55+
decrypted += decipher.final('utf8')
56+
return decrypted
4757
} catch (err) {
4858
return err
4959
}

app/models/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const mongoose = require('mongoose')
2-
const bcrypt = require('bcrypt-nodejs')
2+
const bcrypt = require('bcrypt')
33
const validator = require('validator')
44
const mongoosePaginate = require('mongoose-paginate-v2')
55

@@ -83,7 +83,7 @@ const UserSchema = new mongoose.Schema(
8383
)
8484

8585
const hash = (user, salt, next) => {
86-
bcrypt.hash(user.password, salt, null, (error, newHash) => {
86+
bcrypt.hash(user.password, salt, (error, newHash) => {
8787
if (error) {
8888
return next(error)
8989
}

config/mongo.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = () => {
1010
DB_URL,
1111
{
1212
keepAlive: true,
13-
reconnectTries: Number.MAX_VALUE,
1413
useNewUrlParser: true,
1514
useUnifiedTopology: true
1615
},

data/1.users/user.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,21 @@ module.exports = [
1717
urlGitHub: faker.internet.url(),
1818
createdAt: faker.date.past(),
1919
updatedAt: faker.date.recent()
20+
},
21+
{
22+
_id: new ObjectID('5aa1c2c35ef7a4e97b5e995b'),
23+
name: 'Simple user',
24+
email: 'user@user.com',
25+
password: '$2a$05$2KOSBnbb0r.0TmMrvefbluTOB735rF/KRZb4pmda4PdvU9iDvUB26',
26+
role: 'user',
27+
verified: true,
28+
verification: '3d6e072c-0eaf-4239-bb5e-495e6486148d',
29+
city: 'Bucaramanga',
30+
country: 'Colombia',
31+
phone: '123123',
32+
urlTwitter: faker.internet.url(),
33+
urlGitHub: faker.internet.url(),
34+
createdAt: faker.date.past(),
35+
updatedAt: faker.date.recent()
2036
}
2137
]

0 commit comments

Comments
 (0)