-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbcrypt.js
34 lines (31 loc) · 1011 Bytes
/
bcrypt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var bcrypt = require('bcryptjs');
function hashPassword(plainTextPassword) {
return new Promise(function(resolve, reject) {
bcrypt.genSalt(function(err, salt) {
if (err) {
return reject(err);
}
// console.log(salt);
bcrypt.hash(plainTextPassword, salt, function(err, hash) {
if (err) {
return reject(err);
}
// console.log(hash);
resolve(hash);
});
});
});
}
function checkPassword(textEnteredInLoginForm, hashedPasswordFromDatabase) {
return new Promise(function(resolve, reject) {
bcrypt.compare(textEnteredInLoginForm, hashedPasswordFromDatabase, function(err, doesMatch) {
if (err) {
reject(err);
} else {
resolve(doesMatch);
}
});
});
}
module.exports.hashPassword = hashPassword;
module.exports.checkPassword = checkPassword;