Generating xkcd passwords in PHP

    The famous xkcd comic tells us that a password that consists of 4 frequently used words is easy to remember and hard to guess.

    Translation , original

    All current implementations of this method of generating passwords are designed for English words, which means that passwords are more difficult 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:
    • English words (for example, “idea critic happy chinese”);
    • Russian words (for example, “powder earth zero dress”);
    • transliterated Russian words (for example, "vysota razum bumazhka razmer").

    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 line similar to:


    For each list of words, there is a synonym for quick access:

    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 English words based on the corpus of modern American English .

    An example output is idea critic happy chinese .

    Russian words (WordList \ Ru)

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

    An example of a conclusion is 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 (q, n, b, b) are excluded.

    An example output is vysota razum bumazhka razmer .


    You can try the library here .

    Implementation with these lists of words in JS ( source , author - perevedko ).

    Also popular now: