简体   繁体   English

JavaScript中的人类可说出密码生成器

[英]Human speakable password generator in JavaScript

I am in the process of developing a script that generates human-speakable strings for use in passwords. 我正在开发一个脚本,用于生成用于密码的人类可说字符串。 I am only concerned with English-sounding phrases. 我只关心英语发音的短语。 So far I have come up with the notion of different arrays: 到目前为止,我已经提出了不同数组的概念:

vowels = ['a','e','i','o','u'];
single_consonants = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z'];
double_consonants_leading = ['Bh','Bl','Br','By','Ch','Cl','Cr','Cy','Dr','Dw','Dy','Fl','Fr','Fy','Gh','Gl','Gn','Gr','Gw','Gy','Hy','Jy','Kn','Kr','Kw','Ky','Ly','Mc','Mn','Mr','My','Ny','Ph','Pl','Pn','Pr','Ps','Py','Q','Rh','Ry','Sc','Sh','Sk','Sl','Sm','Sn','Sp','St','Sv','Sw','Sy','Th','Tr','Ts','Tw','Ty','Vr','Vy','Wh','Wr','Wy','Xy','Y','Z'];
double_consonants_trailing = [...'ch'...];
tripple_consonants_leading = [...'Dry','Fly'...];
tripple_consonants_trailing = [...'rch'...];

I will then define a set of rules to concatenate elements from these arrays to create strings but not necessarily words that you would find in the dictionary. 然后,我将定义一组规则来连接这些数组中的元素以创建字符串,但不一定是您在字典中找到的字。

An example is: " Frug-Spunner-Snow-Drive " 一个例子是:“ Frug-Spunner-Snow-Drive

Another alternative is to use a list of words found in the dictionary, however, my first thought on that is that it is a finite list. 另一个选择是使用字典中的单词列表,但是,我首先想到的是它是一个有限列表。 As soon as someone knows which list you are generating strings from it will inevitably reduce the time taken to crack it. 只要有人知道你从哪个列表生成字符串就会不可避免地减少破解它的时间。

My solution will not only create words found in the dictionary but strings that sound like words. 我的解决方案不仅会创建字典中的单词,还会创建听起来像单词的字符串。

function generateString(length)
{
.
.
.
return randomString;
}

generateString(7);

outputs: "Brownen" (a random string) 输出: “Brownen”(随机字符串)

The function will take an argument length and return a string of that length, it could be improved by accepting more arguments such as how many parts to use and the separator to be used between those parts . 该函数将采用参数长度并返回该长度的字符串,可以通过接受更多参数来改进,例如要使用多少部分以及在这些部分之间使用的分隔符

function generateString(parts,lengthOfPart,separator)
{
.
.
.
return randomString;
}

generateString(4,5,"-");

outputs: "Crown-Drive-Knife-Gnome" (4 strings, each 5 characters long split by a hypen) 输出: “Crown-Drive-Knife-Gnome”(4个字符串,每个5个字符长,由一个超级分隔)

This is what I have so far, and the question itself is a work in progress. 这是我到目前为止所做的,问题本身就是一项正在进行的工作。 I would like to make sure that I am on the right track. 我想确保我走在正确的轨道上。

My question is: Is this overkill? 我的问题是:这有点矫枉过正吗? What are the pros and cons? 优缺点都有什么? And ultimately, how will I go about developing this in JavaScript? 最后,我将如何在JavaScript中开发它?

Edit 1 (13/11/2013) 编辑1(13/11/2013)

I have since found an article here: http://www.baekdal.com/insights/password-security-usability that describes using a list of common words, but as long as three+ words are used at any given time then it is very secure as the time it takes to break it is so long the thing you are trying to protect will be of little value. 我在这里发现了一篇文章: http//www.baekdal.com/insights/password-security-usability描述了使用常用单词列表,但只要在任何给定时间使用三个+单词就可以了因为打破它所花费的时间很长,所以你想要保护的东西是没有多大价值的。

Edit 2 (10:10 14/11/2013) 编辑2(10:10 14/11/2013)

I have found another article referring to Markov Chain generator http://www.soliantconsulting.com/blog/2013/02/draft-title-generator-using-markov-chains in Javascript, but again the text is generated from a source text . 我在Javascript中找到另一篇引用马尔可夫链发生器http://www.soliantconsulting.com/blog/2013/02/draft-title-generator-using-markov-chains的文章,但同样文本是从源文本生成的。 Is this possible without it and by defining rules. 如果没有它并通过定义规则,这是否可能。

I think a good approach might be to use a Markov Chain that is generated from a large body of English text. 我认为一个好方法可能是使用由大量英文文本生成的马尔可夫链。 A Markov Chain is basically a probabilistic construct which is dependent upon the source from which it is generated, so you are likely to get many English-like words that are pronounceable. 马尔可夫链基本上是一个概率构造,它依赖于它产生的来源,所以你可能会得到许多类似英语的单词。 In a Markov Chain, you have a state from which you can transition into many other states based on a probability. 在马尔可夫链中,您有一个状态,您可以根据概率转换到许多其他状态。 Since your Markov Chain will be based on English letters from a body of English text, transitions from one letter to another letter will be more probable than a transition to a different one. 由于您的马尔可夫链将基于英文文本正文中的英文字母,因此从一个字母到另一个字母的转换比转换到另一个字母更有可能。 For example, it is more likely to transition from c to a or o , than from c to z or x . 例如,它更可能从c转换为ao ,而不是从czx I have a simple Perl script that generates Markov Chains based on words or letters and I was able to get the following "words" that seem to be pretty pronounceable: 我有一个简单的Perl脚本 ,它根据单词或字母生成马尔可夫链,我能够得到以下似乎非常明显的“单词”:

Engulary 
Beavy 
Lan 
Irstatinval
Bassions
Assish 
Forld  
Anturopean 
Cought 
Froot 
Thation 

Keep in mind though that the entropy is limited by the source material, so it is better to have a large body that you're generating words from. 请记住,虽然熵受到源材料的限制,但最好有一个大的身体,你正在生成单词。 Taking a pointer from the xkcd password generator mentioned by Diodeus , you can combine two or more of these words into pronounceable but nonsensical phrase, that can be a password as well. Diodeus提到的xkcd密码生成器获取指针 ,您可以将这些单词中的两个或多个组合成可发音但无意义的短语,也可以是密码。

Simple example without words list (only letters defined) for people with very good memory ... To get human speakable words, more rules should be added like 4 vowels together. 没有单词列表(只有字母定义)的简单例子,对于记忆力非常好的来说 ......为了获得人类可说的单词,应该添加更多的规则,就像4个元音一样。 Results 结果

Diecrue - Okeiae - Auasvei
Aovaua - Biaeeo - Suwien
Aiasmea - Aueglou - Koiroa
Doiiui - Domeab - Slokaoa
Oeiuju - Yootraa - Koaeua
Qagwisva - Hiexau - Yovaca
Fleeaee - Peaoui - Xafriaa
Vaaute - Iqovai - Naaaesn
Yauehe - Ueeguu - Mrouiepr
Smikreua - Friusnut - Aoqiji

main code: http://jsfiddle.net/mMZ3Y/ 主要代码: http//jsfiddle.net/mMZ3Y/

function get_password_word(n){
    var data1 = ['a','e','i','o','u'];
    var data2 = ['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z'];
    var data3 = ['bl','br','cl','cr','dr','dw','fl','fr','gl','gr','gw','kn','kr','kw','mr','ph','pl','pn','pr','ps','sc','sh','sk','sl','sm','sn','sp','st','sv','sw','tr','ts','wh'];

    var str = '';
    var last = '';
    for(var i = 0; i < n; i++){
        var type = getRandomInt(1, 10);
        //avoiding some cases
        if(last == 3)
            type = 1;
        if(last == 2)
            type = 1;
        if(last == 1 && getRandomInt(1, 2) == 1)
            type = 2;
        //generate
        if(type < 4){ //40%
            str += data1[getRandomInt(0, data1.length-1)];
            last = 1;
            }
        else if(type < 9){  //40%
            str += data2[getRandomInt(0, data2.length-1)];
            last = 2;
            }
        else{ //20%
            str += data3[getRandomInt(0, data3.length-1)];
            last = 3;
            }
        }
    str = str.charAt(0).toUpperCase() + str.slice(1);
    return str;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM