mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Added lib.security.password lib
no issue - move password hashing and password comparison to lib/security/password - added two unit test - FYI: password hashing takes ~100ms - we could probably mock password hashing in certain cases when unit testing
This commit is contained in:
parent
72911862e7
commit
5d1a4418bd
@ -15,5 +15,9 @@ module.exports = {
|
|||||||
|
|
||||||
get identifier() {
|
get identifier() {
|
||||||
return require('./identifier');
|
return require('./identifier');
|
||||||
|
},
|
||||||
|
|
||||||
|
get password() {
|
||||||
|
return require('./password');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
18
ghost/security/lib/password.js
Normal file
18
ghost/security/lib/password.js
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports.hash = function hash(plainPassword) {
|
||||||
|
const bcrypt = require('bcryptjs'),
|
||||||
|
bcryptGenSalt = Promise.promisify(bcrypt.genSalt),
|
||||||
|
bcryptHash = Promise.promisify(bcrypt.hash);
|
||||||
|
|
||||||
|
return bcryptGenSalt().then(function (salt) {
|
||||||
|
return bcryptHash(plainPassword, salt);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.compare = function compare(plainPassword, hashedPassword) {
|
||||||
|
const bcrypt = require('bcryptjs'),
|
||||||
|
bcryptCompare = Promise.promisify(bcrypt.compare);
|
||||||
|
|
||||||
|
return bcryptCompare(plainPassword, hashedPassword);
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user