📜 ⬆️ ⬇️

Generating xkcd passwords in PHP

The famous xkcd comic tells us that the password, which consists of 4 frequently used words, is easy to remember and difficult to find.


Translation , original

All current implementations of this method of generating passwords are designed for English words, which means that passwords are harder to remember in Russian. I armed myself with a frequency dictionary of the Russian language, and made a PHP library that supports the generation of passwords from several sets of words:

Code and word lists on github .
')

Installation using composer


{ "require": { "barzo/password-generator": "dev-master" } } 

Password generation


Passwords are generated by the static function Generator :: generate , which takes three parameters: a list of words, a password length (number of words) and a word separator. For example, generating a password from 5 transliterated words separated by a hyphen:

 $wordList = new Barzo\Password\WordList\RuTranslit(); echo Generator::generate($wordList, 5, '-'); 

The output will contain a string similar to:

  dovod-gore-sever-nomer-druzhka 

For each word list there is a synonym for a quick call:

 echo Barzo\Password\Generator::generateEn(); echo Barzo\Password\Generator::generateRuTranslit(); echo Barzo\Password\Generator::generateRu(); 


Word lists


English words (WordList \ En)

A list of the 2048 most frequently used words of the English language based on the corpus of modern American English .

Example output - idea critic happy chinese .

Russian words (WordList \ Ru)

A list of 2048 most frequently used Russian nouns on the basis of the national corpus of the Russian language .

An example of output is a powder ground zero dress .

Russian transliteration (WordList \ RuTranslit)

A list of 2048 words based on the previous list, from which words that contain ambiguous letters for transliteration are excluded (q, y, b, b).

Example output - vysota razum bumazhka razmer .

Demo


You can try the library here .

Implementation with these lists of words on JS ( source code , the author is perevedko ).

Source: https://habr.com/ru/post/232157/


All Articles