Change node bcrypt package from bcrypt-nodejs to bcrypt. Change response message on invalid username/pass and changed to bcrypt syntax for compare and hash.
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
"bcrypt-nodejs": "^0.0.3",
|
"bcrypt": "^3.0.6",
|
||||||
"body-parser": "~1.18.2",
|
"body-parser": "~1.18.2",
|
||||||
"cross-env": "~5.1.4",
|
"cross-env": "~5.1.4",
|
||||||
"express": "~4.16.0",
|
"express": "~4.16.0",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const bcrypt = require('bcrypt-nodejs');
|
const bcrypt = require('bcrypt');
|
||||||
const UserRepository = require('src/user/userRepository');
|
const UserRepository = require('src/user/userRepository');
|
||||||
|
|
||||||
class UserSecurity {
|
class UserSecurity {
|
||||||
@@ -35,7 +35,7 @@ class UserSecurity {
|
|||||||
return Promise.resolve()
|
return Promise.resolve()
|
||||||
.then(() => this.userRepository.retrieveHash(user))
|
.then(() => this.userRepository.retrieveHash(user))
|
||||||
.then(hash => UserSecurity.compareHashes(hash, clearPassword))
|
.then(hash => UserSecurity.compareHashes(hash, clearPassword))
|
||||||
.catch(() => { throw new Error('Wrong username or password.'); });
|
.catch(() => { throw new Error('Incorrect username or password.'); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,12 +46,10 @@ class UserSecurity {
|
|||||||
*/
|
*/
|
||||||
static compareHashes(hash, clearPassword) {
|
static compareHashes(hash, clearPassword) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
bcrypt.compare(clearPassword, hash, (error, matches) => {
|
bcrypt.compare(clearPassword, hash, (error, match) => {
|
||||||
if (matches === true) {
|
if (match)
|
||||||
resolve();
|
resolve()
|
||||||
} else {
|
reject()
|
||||||
reject();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -63,7 +61,8 @@ class UserSecurity {
|
|||||||
*/
|
*/
|
||||||
static hashPassword(clearPassword) {
|
static hashPassword(clearPassword) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
bcrypt.hash(clearPassword, null, null, (error, hash) => {
|
const salatRounds = 10;
|
||||||
|
bcrypt.hash(clearPassword, saltRounds, (error, hash) => {
|
||||||
resolve(hash);
|
resolve(hash);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user