Skip to content

Development #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 16, 2020
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dist: xenial
language: node_js
node_js:
- '8'
- '10'
cache:
npm: true
services:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## v8.0.1 (March 16, 2020)

- NPM updated

## v8.0.0 (March 16, 2020)

- This major version requires node 10+ because new bcrypt lib
- Use of bcrypt lib
- New test for users
- NPM updated

## v7.1.2 (January 12, 2020)

- Added cross-env to solve windows envionment issues
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Feel free to send me a tweet <https://twitter.com/davellanedam>, share this with

## Requirements

- Node.js **8+**
- Node.js **10+**
- MongoDB **3.6+**
- Redis **5.0+**

Expand Down
28 changes: 19 additions & 9 deletions app/middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const crypto = require('crypto')
const algorithm = 'aes-256-ecb'

const secret = process.env.JWT_SECRET
const algorithm = 'aes-192-cbc'
// Key length is dependent on the algorithm. In this case for aes192, it is
// 24 bytes (192 bits).
const key = crypto.scryptSync(secret, 'salt', 24)
const iv = Buffer.alloc(16, 0) // Initialization crypto vector

module.exports = {
/**
Expand All @@ -27,23 +32,28 @@ module.exports = {
* Encrypts text
* @param {string} text - text to encrypt
*/

encrypt(text) {
const cipher = crypto.createCipher(algorithm, secret)
let crypted = cipher.update(text, 'utf8', 'hex')
crypted += cipher.final('hex')
return crypted
const cipher = crypto.createCipheriv(algorithm, key, iv)

let encrypted = cipher.update(text, 'utf8', 'hex')
encrypted += cipher.final('hex')

return encrypted
},

/**
* Decrypts text
* @param {string} text - text to decrypt
*/

decrypt(text) {
const decipher = crypto.createDecipher(algorithm, secret)
const decipher = crypto.createDecipheriv(algorithm, key, iv)

try {
let dec = decipher.update(text, 'hex', 'utf8')
dec += decipher.final('utf8')
return dec
let decrypted = decipher.update(text, 'hex', 'utf8')
decrypted += decipher.final('utf8')
return decrypted
} catch (err) {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions app/models/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const mongoose = require('mongoose')
const bcrypt = require('bcrypt-nodejs')
const bcrypt = require('bcrypt')
const validator = require('validator')
const mongoosePaginate = require('mongoose-paginate-v2')

Expand Down Expand Up @@ -83,7 +83,7 @@ const UserSchema = new mongoose.Schema(
)

const hash = (user, salt, next) => {
bcrypt.hash(user.password, salt, null, (error, newHash) => {
bcrypt.hash(user.password, salt, (error, newHash) => {
if (error) {
return next(error)
}
Expand Down
1 change: 0 additions & 1 deletion config/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module.exports = () => {
DB_URL,
{
keepAlive: true,
reconnectTries: Number.MAX_VALUE,
useNewUrlParser: true,
useUnifiedTopology: true
},
Expand Down
16 changes: 16 additions & 0 deletions data/1.users/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,21 @@ module.exports = [
urlGitHub: faker.internet.url(),
createdAt: faker.date.past(),
updatedAt: faker.date.recent()
},
{
_id: new ObjectID('5aa1c2c35ef7a4e97b5e995b'),
name: 'Simple user',
email: '[email protected]',
password: '$2a$05$2KOSBnbb0r.0TmMrvefbluTOB735rF/KRZb4pmda4PdvU9iDvUB26',
role: 'user',
verified: true,
verification: '3d6e072c-0eaf-4239-bb5e-495e6486148d',
city: 'Bucaramanga',
country: 'Colombia',
phone: '123123',
urlTwitter: faker.internet.url(),
urlGitHub: faker.internet.url(),
createdAt: faker.date.past(),
updatedAt: faker.date.recent()
}
]
Loading