JavaScript password generator
My password generator has gone through several different rewrites in various languages. This one is a very good way to add password generation to a web page, to help users create good, secure passwords.
Since the passwords are meant to be based on pronouncable words, this generator can present both the final password and the non-transformed version, to aid in memorization.
Try it out here!
HTML code
<input onclick="javascript:autopwd('autopwd','password');" value="Generate" type="button" /><br />
<span id="autopwd"></span>JavaScript code
Lots of text removed. Refer to the attached code archive.
var nomes = 'abouboutabovboveabraabrabracracaacadcadaadabdabrabraabusbuseusedacceccepcepteptep'; nomes += 'tedacciccidcideidendentaccuccuscuseuserachechesacqucquaquaiuainaintintantantancan'; // ... nomes += 'oungyouryouroursyouroursurserselselfyouyouyouyou'; var wstart = 'abouabovabraabraabusacceacciaccuacheacquacquacroactoadreadroadvaadviaeroaffeafraa'; wstart += 'friafriafteafteagaiagaiagaiaheaaintalanaliealivallcalmoalonalonalonalphalrealrial'; // ... wstart += 'yearyearyellyestymcayongyoubyounyouryouryouryouy'; function randpw(len) { var replaceable='eghiosl'; var replacement='364105!'; var nomesize=4; var n_nomes=nomes.length / nomesize; var n_wstart=wstart.length / nomesize; var found=false; var pwd=''; while (!found) { var wstartindex=Math.round(n_wstart * Math.random()) * nomesize; pwd=wstart.substr(wstartindex, nomesize); var iterations=0; while ((++iterations) < 200 && pwd.length < len) { var it2=2000; do { var k=Math.round(n_nomes * Math.random()) * nomesize; nome=nomes.substr(k, nomesize); } while ((--it2) > 0 && (nome.substr(0, nomesize-1) != pwd.substr(pwd.length-(nomesize-1), nomesize-1))); if (it2 == 0) iterations=200; else { pwd += nome.substr(nomesize-1, 1); } } if (iterations < 200) { found=true; } } var newpwd=''; for (j=0; j<pwd.length; j++) { var x=pwd.substr(j,1); if (Math.random() > 0.6) { if ((n=replaceable.indexOf(x)) != -1) { x = replacement.substr(n, 1); } else { x = x.toUpperCase(); } } newpwd = newpwd+x; } return [pwd, newpwd]; } function autopwd(textfield, pwdfield) { var el1=document.getElementById(textfield); var el2=document.getElementById(pwdfield); var pwd=randpw(8); var str=pwd[1]+' (pronounced like \''+pwd[0]+'\')'; if (el1.firstChild == null) el1.appendChild(document.createTextNode(str)); else el1.firstChild.nodeValue=str; el2.value=pwd[1]; pwdcheck_update(); return false; }
The code doesn't use innerHTML and even works in the Nintendo Wii Opera browser.
| Attachment | Size |
|---|---|
| autopwd.js.gz | 12.56 KB |


Recent comments
1 year 4 weeks ago
1 year 31 weeks ago
1 year 34 weeks ago
1 year 39 weeks ago
1 year 39 weeks ago
2 years 2 weeks ago
2 years 13 weeks ago
2 years 13 weeks ago
2 years 13 weeks ago
2 years 14 weeks ago