-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
28 lines (25 loc) · 846 Bytes
/
utils.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
var crypto = require('crypto');
var genRandomString = function(length){
return crypto.randomBytes(Math.ceil(length/2))
.toString('hex')
.slice(0,length);
};
var sha256 = function(password, salt){
var hash = crypto.createHmac('sha256', salt);
hash.update(password);
var value = hash.digest('hex');
return { salt:salt, passwordHash:value };
};
function saltHashPassword(userpassword,username) {
// var salt = genRandomString(16);
var salt = username;
var passwordData = sha256(userpassword, salt);
console.log('UserPassword = '+userpassword);
console.log('Passwordhash = '+passwordData.passwordHash);
return passwordData.passwordHash;
}
// saltHashPassword('MYPASSWORD');
// saltHashPassword('MYPASSWORD');
module.exports = {
saltHashPassword,
}