-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
62 lines (55 loc) · 2.07 KB
/
test.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var scrypt = require("./");
var Promise = require("bluebird");
/* Using Promises */
var theHash;
Promise.try(function(){
return scrypt.hash("secretpassword");
}).then(function(hash){
console.log("The hash is " + hash);
theHash = hash;
/* Now let's see if it verifies - number 1 is correct. */
return scrypt.verifyHash("secretpassword", theHash);
}).then(function(){
console.log("Number 1 was correct!");
}).catch(scrypt.PasswordError, function(err){
console.log("Number 1 was wrong!");
}).then(function(){
/* And let's see if it fails correctly - number 2 is wrong. */
return scrypt.verifyHash("wrongpassword", theHash);
}).then(function(){
console.log("Number 2 was correct!");
}).catch(scrypt.PasswordError, function(err){
console.log("Number 2 was wrong!", err);
}).then(function(){
return scrypt.verifyHash("secretpassword", "c2NyeXB0AAwAAAAIAAAAAT8rdRZx8U1zzOnl0kor8x0MJK0SjXT277JgNYPWTzUiCchRWnTffPE23ZB8PwPDA4ckcSlDrNnrxMyH2fN2iMYbYS5sTnPHl2qLKgsiLsGr");
}).then(function(){
console.log("Known-good hash was correct!");
}).catch(scrypt.PasswordError, function(err){
console.log("Known-good hash was wrong!", err);
}).then(function(){
return scrypt.verifyHash("wrongpassword", "c2NyeXB0AAwAAAAIAAAAAT8rdRZx8U1zzOnl0kor8x0MJK0SjXT277JgNYPWTzUiCchRWnTffPE23ZB8PwPDA4ckcSlDrNnrxMyH2fN2iMYbYS5sTnPHl2qLKgsiLsGr");
}).then(function(){
console.log("Known-bad hash was correct!");
}).catch(scrypt.PasswordError, function(err){
console.log("Known-bad hash was wrong!", err);
});
/* Using nodebacks */
scrypt.hash("secretpassword", {}, function(err, hash){
console.log("The hash is " + hash);
/* Now let's see if it verifies - number 1 is correct. */
scrypt.verifyHash("secretpassword", hash, function(err, result){
if(err) {
console.log("Number 1 was wrong!", err);
} else {
console.log("Number 1 was correct!");
}
/* And let's see if it fails correctly - number 2 is wrong. */
scrypt.verifyHash("wrongpassword", hash, function(err, result){
if(err) {
console.log("Number 2 was wrong!", err);
} else {
console.log("Number 2 was correct!");
}
});
});
});