-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnp.js
34 lines (31 loc) · 969 Bytes
/
np.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 mosquittoPBKDF2 = require('./mosquitto_pbkdf2');
var promptly = require('promptly');
// do not allow empty password here...
var errFunc = function(err) {
// err object not set for some reason
console.log('Password must not be empty');
};
var notEmptyValidator = function (value) {
if (value.length < 1) {
throw new Error('Password must not be empty');
}
return value;
};
var options = {
validator: notEmptyValidator,
replace: '*',
retry: false,
default: ''
};
promptly.password('Enter password: ', options).then(function(pwd1) {
promptly.password('Re-enter password: ', options).then(function(pwd2) {
if (pwd1 !== pwd2) {
console.log('Passwords do not match!');
}
else {
mosquittoPBKDF2.createPasswordAsync(pwd1, function(newPBKDF2Password){
console.log('New PBKDF2 hash: '+newPBKDF2Password);
});
}
}, errFunc);
}, errFunc);