Password Generator
After making this password generator, I decided to make another one that used a list of words to create a random combination of words for a password.
I finished it last night, and you can view it at maxpelic.com/examples/password_word_generator.html.
Compression
I started by creating a Python script that compressed the list of words I planned on using. First, it groups words by the first two letters and creates sections with them, separated by capital letters.
For example, the words total
, toenail
, today
, and topical
would become toTalEnailDayPical
. the first two letters are the common letters all the words share, and the rest of the letters are combinations that can be added to create a real word.
Next, I combined all the sections, separated by a .
, and replaced the most common letter combinations with various symbols. For example, toTalEnailPical
might become toT?EnailPic?
.
Then I printed out the symbols, replacements, and compressed string to place in my HTML file. Here’s an example of the first part of the string: abAonIl@yOr!OO^RoadSen]Su:Su: S>b...
(I removed some characters that weren’t showing up right…)
Decompression
To decompress the list, I basically do the same process in reverse. Here’s a basic implementation of the decompression:
function decodeSection(section){
let start = section.substr(0, 2), list = [];
section = section.substr(2).split(/(?!^)(?=[A-Z])/g);
for(let i = 0; i < section.length; i++){
list.push((start + section[i]).toLowerCase());
}
return list;
}
function getDecodedWordList(){
let wordlist = getWordList(), i, words=[];
const to = ['tion','atio','sion','ionN','ionS','ionT','ionP','ionO','ionR'], from = '123456789';
for(i=0;i<from.length;i++)
while(wordlist.indexOf(from[i]) > -1)
wordlist = wordlist.replace(from[i], to[i]);
wordlist = wordlist.split('.');
for(i=0;i<wordlist.length;i++)
words = words.concat(decodeSection(wordlist[i]));
return words;
}
Picking words
From there, it’s pretty easy to pick words. I used window.crypto
, a cryptographically secure way to generate random numbers. Assuming window.words
contains the full list of words, this is how I generated random words:
let randomNumbers = new Uint32Array(3);
window.crypto.getRandomValues(randomNumbers);
let newWords = [];
for(let i = 0; i < 3; i++){
newWords.push(window.words[randomNumbers[i] % window.words.length]);
}
console.log(randomWords);
Learn more
Feel free to look under the hood of the password generator and email me with any questions or suggestions you have ([email protected])