-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash-password.node.js
More file actions
22 lines (16 loc) · 989 Bytes
/
hash-password.node.js
File metadata and controls
22 lines (16 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var pass = {};
pass.saltlen = 64;
pass.keylen = 128;
pass.digest = 'sha512';
pass.iterations = 500_000;
pass.gen = function(password,salt){
salt = salt||crypto.randomBytes(pass.saltlen).toString('base64');
var buf = crypto.pbkdf2Sync(password,salt,pass.iterations,pass.keylen,pass.digest);
var hash = buf.toString('base64');
return {salt,hash};
}//hash
pass.verify = function(hash,salt,password){
var hash2 = pass.gen(password,salt).hash
var result = (hash==hash2);
return result;
}//verify