-
Notifications
You must be signed in to change notification settings - Fork 0
/
diceware-adibro.js
44 lines (37 loc) · 986 Bytes
/
diceware-adibro.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
let wordList = require("./diceware-adibro-wordlist");
let defOptions = {
numOfWords: 5,
wordSeperator: " "
};
let options = {
numOfWords: 5,
wordSeperator: " "
};
var diceware = function() {};
diceware.prototype.randomWord = function() {
let keyString = "";
for (let i = 0; i < 5; i++) {
keyString += Math.floor(Math.random() * (6 - 1 + 1) + 1);
}
return wordList[keyString];
};
diceware.prototype.preparePassword = function(opts) {
if (opts) {
if (opts.hasOwnProperty("numOfWords")) options.numOfWords = opts.numOfWords;
if (opts.hasOwnProperty("wordSeperator"))
options.wordSeperator = opts.wordSeperator;
} else {
options = defOptions;
}
let loop = 0;
let password = "";
while (loop < options.numOfWords) {
password +=
diceware.prototype.randomWord() +
(loop < options.numOfWords - 1 ? options.wordSeperator : "");
loop++;
}
options = defOptions;
return password;
};
module.exports = diceware;