Skip to content

Instantly share code, notes, and snippets.

@nicwolff
Created December 1, 2011 07:36
Show Gist options
  • Save nicwolff/1414689 to your computer and use it in GitHub Desktop.
Save nicwolff/1414689 to your computer and use it in GitHub Desktop.
Password generator bookmarklet
javascript:var%20b64pad='';var%20chrsz=8;function%20b64_sha1(s)%7Breturn%20binb2b64(core_sha1(str2binb(s),s.length*chrsz));%7Dfunction%20core_sha1(x,len)%7Bx%5Blen%3E%3E5%5D%7C=0x80%3C%3C(24-len);x%5B((len+64%3E%3E9)%3C%3C4)+15%5D=len;var%20w=Array(80);var%20a=1732584193;var%20b=-271733879;var%20c=-1732584194;var%20d=271733878;var%20e=-1009589776;for(var%20i=0;i%3Cx.length;i+=16)%7Bvar%20olda=a;var%20oldb=b;var%20oldc=c;var%20oldd=d;var%20olde=e;for(var%20j=0;j%3C80;j++)%7Bif(j%3C16)w%5Bj%5D=x%5Bi+j%5D;else%20w%5Bj%5D=rol(w%5Bj-3%5D%5Ew%5Bj-8%5D%5Ew%5Bj-14%5D%5Ew%5Bj-16%5D,1);var%20t=safe_add(safe_add(rol(a,5),sha1_ft(j,b,c,d)),safe_add(safe_add(e,w%5Bj%5D),sha1_kt(j)));e=d;d=c;c=rol(b,30);b=a;a=t;%7Da=safe_add(a,olda);b=safe_add(b,oldb);c=safe_add(c,oldc);d=safe_add(d,oldd);e=safe_add(e,olde);%7Dreturn%20Array(a,b,c,d,e);%7Dfunction%20sha1_ft(t,b,c,d)%7Bif(t%3C20)return%20(b&c)%7C((~b)&d);if(t%3C40)return%20b%5Ec%5Ed;if(t%3C60)return%20(b&c)%7C(b&d)%7C(c&d);return%20b%5Ec%5Ed;%7Dfunction%20sha1_kt(t)%7Breturn%20(t%3C20)?1518500249:(t%3C40)?1859775393:(t%3C60)?-1894007588:-899497514;%7Dfunction%20safe_add(x,y)%7Bvar%20lsw=(x&0xFFFF)+(y&0xFFFF);var%20msw=(x%3E%3E16)+(y%3E%3E16)+(lsw%3E%3E16);return%20(msw%3C%3C16)%7C(lsw&0xFFFF);%7Dfunction%20rol(num,cnt)%7Breturn%20(num%3C%3Ccnt)%7C(num%3E%3E%3E(32-cnt));%7Dfunction%20str2binb(str)%7Bvar%20bin=Array();var%20mask=(1%3C%3Cchrsz)-1;for(var%20i=0;i%3Cstr.length*chrsz;i+=chrsz)bin%5Bi%3E%3E5%5D%7C=(str.charCodeAt(i/chrsz)&mask)%3C%3C(24-i);return%20bin;%7Dfunction%20binb2b64(binarray)%7Bvar%20tab='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';var%20str='';for(var%20i=0;i%3Cbinarray.length*4;i+=3)%7Bvar%20triplet=(((binarray%5Bi%3E%3E2%5D%3E%3E8*(3-i%254))&0xFF)%3C%3C16)%7C(((binarray%5Bi+1%3E%3E2%5D%3E%3E8*(3-(i+1)%254))&0xFF)%3C%3C8)%7C((binarray%5Bi+2%3E%3E2%5D%3E%3E8*(3-(i+2)%254))&0xFF);for(var%20j=0;j%3C4;j++)%7Bif(i*8+j*6%3Ebinarray.length*32)str+=b64pad;else%20str+=tab.charAt((triplet%3E%3E6*(3-j))&0x3F);%7D%7Dreturn%20str;%7Dfunction%20doIt()%7Bvar%20master=window.prompt('Enter%20your%20master%20password');if(master!=''&&master!=null)%7Bhost=document.location.href.match(/http(s*):%5C/%5C/(%5B%5E/%5D+)/)%5B2%5D;if(sld=host.match(/(%5B%5E.%5D+%5C.(%5Ba-z%5D%5Ba-z%5D%5Ba-z%5D+%7Ca(m%7Cs%7Cx)%7Cbg%7Cc(f%7Cl%7Cz)%7Cd(e%7Cj%7Ck)%7Ceu%7Cfm%7Cfo%7Cgl%7Cgm%7Chm%7Cio%7Ckm%7Cla%7Cly%7Cm(d%7Ce%7Cn%7Cp%7Cq%7Cr)%7Cnc%7Cnu%7Cs(i%7Cm%7Cn%7Cr%7Ct%7Cu%7Cz)%7Ctd%7Ctk%7Cuz%7Cvc%7Cvu%7Cws))$/i))%7Bdomain=sld%5B0%5D;%7Delse%7Bdomain=host.match(/(%5B%5E.%5D+%5C.%5B%5E.%5D+%5C.%5Ba-z%5D%5Ba-z%5D)$/i)%5B0%5D;%7Dvar%20i=0,j=0,p=b64_sha1(master+':'+domain).substr(0,8)+'1a',F=document.forms,g=false;for(i=0;i%3CF.length;i++)%7BE=F%5Bi%5D.elements;for(j=0;j%3CE.length;j++)%7BD=E%5Bj%5D;if(D.type=='password')%7BD.value=p;D.focus();g=true;%7Dif(D.type=='text')%7Bif(D.name.toUpperCase().indexOf('PASSWORD')!=-1%7C%7CD.name.toUpperCase().indexOf('PASSWD')!=-1)%7BD.value=p;D.focus();g=true;%7D%7D%7D%7Dif(!g)%7Bwindow.prompt('Your%20password%20for%20'+domain+'%20is',p)%7D%7D%7DdoIt();void(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment