Skip to content

Instantly share code, notes, and snippets.

@vneri
Last active February 16, 2021 17:06
Show Gist options
  • Save vneri/bd6ba986e9ea91bb419d53ef7f1e93a4 to your computer and use it in GitHub Desktop.
Save vneri/bd6ba986e9ea91bb419d53ef7f1e93a4 to your computer and use it in GitHub Desktop.
Create readable, pronounceable, memorable passwords in JavaScript with flexible, translatable dictionaries
if (! window.readablePasswordDictionary){
window.readablePasswordDictionary = [];
}
// you can also provide custom ones, by adding another language set
window.readablePasswordDictionary['de'] =
[
'Anfrage', 'Bestellung', 'Produkt', 'Adam', 'Entdeckung', 'gewisse', 'Gewissen',
'Zeit', 'Socken', 'super', 'Deutschland', 'Berlin', 'Hannover', 'Hamburg',
'zusammen', 'sicher', 'genauso', 'gegen', 'entgegen', 'exzellent', 'aktuell', 'Feier',
'Gestaltung', 'Event', 'eventuell', 'geradeaus', 'Inspektion', 'Sicherheit',
'Angebot', 'passend', 'genial', 'wertvoll', 'intensiv', 'Woche', 'Monat', 'Tag',
'Schraubenzieher', 'Schuhe', 'Jacke', 'Sonnenschein', 'Mondschein', 'erarbeiten',
'Geschichte', 'Glaube', 'Wirkung', 'Interesse', 'Erfindung', 'angefangen',
'Marketing', 'verkauft', 'Umgestaltung', 'Vertretung', 'anfangen', 'trennen',
'finden', 'suchen', 'nachschauen', 'intelligent', 'Installation'
];
if (! window.createReadablePassword){
window.createReadablePassword = function(complexity, language){
// this will create a random password, based on a complexity
// 1: one word and one 4 digits number
// 2: two words and one 4 digits number
if (!window.readablePasswordDictionary[language]){
throw('No dictionary found for the provided language "'+language+'"');
return;
}
var generated = '';
for (var i=0; i<complexity; i++){
var randomIndex = Math.floor(Math.random() * (window.readablePasswordDictionary[language].length));
generated += window.readablePasswordDictionary[language][randomIndex];
if (i<complexity-1){
generated += 999 + Math.floor(Math.random() * (9000));
}
}
return generated;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment