parent
a958c66249
commit
cc65e98940
6 changed files with 87 additions and 13 deletions
32
lib/key_generators/phonetic.js
Normal file
32
lib/key_generators/phonetic.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Draws inspiration from pwgen and http://tools.arantius.com/password
|
||||
var PhoneticKeyGenerator = function(options) {
|
||||
// No options
|
||||
};
|
||||
|
||||
// Generate a phonetic key
|
||||
PhoneticKeyGenerator.prototype.createKey = function(keyLength) {
|
||||
var text = '';
|
||||
for (var i = 0; i < keyLength; i++) {
|
||||
text += (i % 2 == 0) ? this.randConsonant() : this.randVowel();
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
PhoneticKeyGenerator.consonants = 'bcdfghjklmnpqrstvwxy';
|
||||
PhoneticKeyGenerator.vowels = 'aeiou';
|
||||
|
||||
// Get an random vowel
|
||||
PhoneticKeyGenerator.prototype.randVowel = function() {
|
||||
return PhoneticKeyGenerator.vowels[
|
||||
Math.floor(Math.random() * PhoneticKeyGenerator.vowels.length)
|
||||
];
|
||||
};
|
||||
|
||||
// Get an random consonant
|
||||
PhoneticKeyGenerator.prototype.randConsonant = function() {
|
||||
return PhoneticKeyGenerator.consonants[
|
||||
Math.floor(Math.random() * PhoneticKeyGenerator.consonants.length)
|
||||
];
|
||||
};
|
||||
|
||||
module.exports = PhoneticKeyGenerator;
|
14
lib/key_generators/random.js
Normal file
14
lib/key_generators/random.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
var RandomKeyGenerator = function(options) {
|
||||
this.keyspace = options.keyspace || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
};
|
||||
|
||||
// Generate a random key
|
||||
RandomKeyGenerator.prototype.createKey = function(keyLength) {
|
||||
var text = '';
|
||||
for (var i = 0; i < keyLength; i++) {
|
||||
text += this.keyspace.charAt(Math.floor(Math.random() * this.keyspace.length));
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
module.exports = RandomKeyGenerator;
|
Loading…
Add table
Add a link
Reference in a new issue