minor updates and compression

* add password auto-clearing after 60s
* display blank password if either site or password is blank
* switch to sha1
* add license info to passy.js
* created passytiny.js and passytiny.html (which includes passytiny.js already)
This commit is contained in:
swaits committed 2010-11-12 15:24:16 -08:00
1 parent 013377b414
commit 693d0b815e
4 files changed
+132 -3

No files matched your search

+25 -3
View File
@@ -1,13 +1,35 @@
<html>
<head>
<script type='text/javascript' src='jsSHA/src/sha1.js'></script>
<script type='text/javascript' src='passy.js'></script>
<script type='text/javascript' src='passytiny.js'></script>
<script type='text/javascript'>
var password_timer=0;
function ClearPassword()
{
// clear password field and force an update
document.getElementById('password').value = "";
document.getElementById('password').focus();
UpdatePassy();
}
function UpdatePassy()
{
// do password update
var site = document.getElementById('site').value;
var password = document.getElementById('password').value;
document.getElementById('result').value = passy(site,password)[0];
if ( site == "" || password == "" )
{
document.getElementById('result').value = "";
}
else
{
document.getElementById('result').value = passy(site,password)[0];
}
// set timer to clear password field after a minute
if ( password_timer != 0 )
{
clearTimeout(password_timer);
}
password_timer = setTimeout('ClearPassword()',60000);
}
</script>
</head>
+39
View File
@@ -1,3 +1,42 @@
/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
* PUB 180-2 as well as the corresponding HMAC implementation as defined in
* FIPS PUB 198a
*
* Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
(function(){var charSize=8,b64pad="",hexCase=0,str2binb=function(a){var b=[],mask=(1<<charSize)-1,length=a.length*charSize,i;for(i=0;i<length;i+=charSize){b[i>>5]|=(a.charCodeAt(i/charSize)&mask)<<(32-charSize-(i%32))}return b},hex2binb=function(a){var b=[],length=a.length,i,num;for(i=0;i<length;i+=2){num=parseInt(a.substr(i,2),16);if(!isNaN(num)){b[i>>3]|=num<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b},binb2hex=function(a){var b=(hexCase)?"0123456789ABCDEF":"0123456789abcdef",str="",length=a.length*4,i,srcByte;for(i=0;i<length;i+=1){srcByte=a[i>>2]>>((3-(i%4))*8);str+=b.charAt((srcByte>>4)&0xF)+b.charAt(srcByte&0xF)}return str},binb2b64=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+"0123456789+/",str="",length=a.length*4,i,j,triplet;for(i=0;i<length;i+=3){triplet=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(j=0;j<4;j+=1){if(i*8+j*6<=a.length*32){str+=b.charAt((triplet>>6*(3-j))&0x3F)}else{str+=b64pad}}}return str},rotl=function(x,n){return(x<<n)|(x>>>(32-n))},parity=function(x,y,z){return x^y^z},ch=function(x,y,z){return(x&y)^(~x&z)},maj=function(x,y,z){return(x&y)^(x&z)^(y&z)},safeAdd_2=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF),msw=(x>>>16)+(y>>>16)+(a>>>16);return((msw&0xFFFF)<<16)|(a&0xFFFF)},safeAdd_5=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((msw&0xFFFF)<<16)|(f&0xFFFF)},coreSHA1=function(f,g){var W=[],a,b,c,d,e,T,i,t,appendedMessageLength,H=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0],K=[0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6];f[g>>5]|=0x80<<(24-(g%32));f[(((g+65)>>9)<<4)+15]=g;appendedMessageLength=f.length;for(i=0;i<appendedMessageLength;i+=16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];for(t=0;t<80;t+=1){if(t<16){W[t]=f[t+i]}else{W[t]=rotl(W[t-3]^W[t-8]^W[t-14]^W[t-16],1)}if(t<20){T=safeAdd_5(rotl(a,5),ch(b,c,d),e,K[t],W[t])}else if(t<40){T=safeAdd_5(rotl(a,5),parity(b,c,d),e,K[t],W[t])}else if(t<60){T=safeAdd_5(rotl(a,5),maj(b,c,d),e,K[t],W[t])}else{T=safeAdd_5(rotl(a,5),parity(b,c,d),e,K[t],W[t])}e=d;d=c;c=rotl(b,30);b=a;a=T}H[0]=safeAdd_2(a,H[0]);H[1]=safeAdd_2(b,H[1]);H[2]=safeAdd_2(c,H[2]);H[3]=safeAdd_2(d,H[3]);H[4]=safeAdd_2(e,H[4])}return H},jsSHA=function(a,b){this.sha1=null;this.strBinLen=null;this.strToHash=null;if("HEX"===b){if(0!==(a.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}this.strBinLen=a.length*4;this.strToHash=hex2binb(a)}else if(("ASCII"===b)||('undefined'===typeof(b))){this.strBinLen=a.length*charSize;this.strToHash=str2binb(a)}else{return"UNKNOWN TEXT INPUT TYPE"}};jsSHA.prototype={getHash:function(a){var b=null,message=this.strToHash.slice();switch(a){case"HEX":b=binb2hex;break;case"B64":b=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}if(null===this.sha1){this.sha1=coreSHA1(message,this.strBinLen)}return b(this.sha1)},getHMAC:function(a,b,c){var d,keyToUse,i,retVal,keyBinLen,keyWithIPad=[],keyWithOPad=[];switch(c){case"HEX":d=binb2hex;break;case"B64":d=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}keyToUse=hex2binb(a);keyBinLen=a.length*4}else if("ASCII"===b){keyToUse=str2binb(a);keyBinLen=a.length*charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(64<(keyBinLen/8)){keyToUse=coreSHA1(keyToUse,keyBinLen);keyToUse[15]&=0xFFFFFF00}else if(64>(keyBinLen/8)){keyToUse[15]&=0xFFFFFF00}for(i=0;i<=15;i+=1){keyWithIPad[i]=keyToUse[i]^0x36363636;keyWithOPad[i]=keyToUse[i]^0x5C5C5C5C}retVal=coreSHA1(keyWithIPad.concat(this.strToHash),512+this.strBinLen);retVal=coreSHA1(keyWithOPad.concat(retVal),672);return(d(retVal))}};window.jsSHA=jsSHA}());
/*
* passy.js - implementation of passy algorithm javascript, by Stephen Waits
*
* The MIT License
*
* Copyright (c) 2010 Stephen Waits <steve@waits.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* Given a "text" (i.e. "amazon.com") and a "secret" (i.e. "mypassword") return an
* array of four Passy'fied passwords.
+59
View File
@@ -0,0 +1,59 @@
<html>
<head>
<script type='text/javascript'>
(function(){var q=function(a){var c=[],d=a.length*8,b;for(b=0;b<d;b+=8)c[b>>5]|=(a.charCodeAt(b/8)&255)<<24-b%32;return c},r=function(a){var c=[],d=a.length,b,e;for(b=0;b<d;b+=2){e=parseInt(a.substr(b,2),16);if(isNaN(e))return"INVALID HEX STRING";else c[b>>3]|=e<<24-4*(b%8)}return c},m=function(a){var c="",d=a.length*4,b,e;for(b=0;b<d;b+=1){e=a[b>>2]>>(3-b%4)*8;c+="0123456789abcdef".charAt(e>>4&15)+"0123456789abcdef".charAt(e&15)}return c},n=function(a){var c="",d=a.length*4,b,e,j;for(b=0;b<d;b+=
3){j=(a[b>>2]>>8*(3-b%4)&255)<<16|(a[b+1>>2]>>8*(3-(b+1)%4)&255)<<8|a[b+2>>2]>>8*(3-(b+2)%4)&255;for(e=0;e<4;e+=1)c+=b*8+e*6<=a.length*32?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(j>>6*(3-e)&63):""}return c},f=function(a,c){return a<<c|a>>>32-c},o=function(a,c){var d=(a&65535)+(c&65535);return((a>>>16)+(c>>>16)+(d>>>16)&65535)<<16|d&65535},k=function(a,c,d,b,e){var j=(a&65535)+(c&65535)+(d&65535)+(b&65535)+(e&65535);return((a>>>16)+(c>>>16)+(d>>>16)+(b>>>16)+(e>>>16)+
(j>>>16)&65535)<<16|j&65535},u=function(a,c){var d=[],b,e,j,l,p,v,s,g,w,h=[1732584193,4023233417,2562383102,271733878,3285377520],t=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,
1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];
a[c>>5]|=128<<24-c%32;a[(c+65>>9<<4)+15]=c;w=a.length;for(s=0;s<w;s+=16){b=h[0];e=h[1];j=h[2];l=h[3];p=h[4];for(g=0;g<80;g+=1){d[g]=g<16?a[g+s]:f(d[g-3]^d[g-8]^d[g-14]^d[g-16],1);v=g<20?k(f(b,5),e&j^~e&l,p,t[g],d[g]):g<40?k(f(b,5),e^j^l,p,t[g],d[g]):g<60?k(f(b,5),e&j^e&l^j&l,p,t[g],d[g]):k(f(b,5),e^j^l,p,t[g],d[g]);p=l;l=j;j=f(e,30);e=b;b=v}h[0]=o(b,h[0]);h[1]=o(e,h[1]);h[2]=o(j,h[2]);h[3]=o(l,h[3]);h[4]=o(p,h[4])}return h},x=function(a,c){this.strToHash=this.strBinLen=this.sha1=null;if("HEX"===c){if(0!==
a.length%2)return"TEXT MUST BE IN BYTE INCREMENTS";this.strBinLen=a.length*4;this.strToHash=r(a)}else if("ASCII"===c||"undefined"===typeof c){this.strBinLen=a.length*8;this.strToHash=q(a)}else return"UNKNOWN TEXT INPUT TYPE"};x.prototype={getHash:function(a){var c=null,d=this.strToHash.slice();switch(a){case "HEX":c=m;break;case "B64":c=n;break;default:return"FORMAT NOT RECOGNIZED"}if(null===this.sha1)this.sha1=u(d,this.strBinLen);return c(this.sha1)},getHMAC:function(a,c,d){var b;b=[];var e=[];switch(d){case "HEX":d=
m;break;case "B64":d=n;break;default:return"FORMAT NOT RECOGNIZED"}if("HEX"===c){if(0!==a.length%2)return"KEY MUST BE IN BYTE INCREMENTS";c=r(a);a=a.length*4}else if("ASCII"===c){c=q(a);a=a.length*8}else return"UNKNOWN KEY INPUT TYPE";if(64<a/8){c=u(c,a);c[15]&=4294967040}else if(64>a/8)c[15]&=4294967040;for(a=0;a<=15;a+=1){b[a]=c[a]^909522486;e[a]=c[a]^1549556828}b=u(b.concat(this.strToHash),512+this.strBinLen);b=u(e.concat(b),672);return d(b)}};window.jsSHA=x})();
var passy=function(q,r){var m=function(f){var o={"1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")"},k=true;for(i=0;i<f.length;++i)if(/[0-9]/.test(f[i])){if(k)f=f.slice(0,i)+o[f[i]]+f.slice(i+1,f.length);k=!k}k=true;for(i=0;i<f.length;++i)if(/[a-f]/i.test(f[i])){f=f.slice(0,i)+(k?f[i].toUpperCase():f[i].toLowerCase())+f.slice(i+1,f.length);k=!k}return f},n=(new jsSHA(q.toLowerCase(),"ASCII")).getHMAC(r,"ASCII","HEX");return[m(n.slice(0,10)),m(n.slice(10,20)),m(n.slice(20,
30)),m(n.slice(30,40))]};
</script>
<script type='text/javascript'>
var password_timer=0;
function ClearPassword()
{
// clear password field and force an update
document.getElementById('password').value = "";
document.getElementById('password').focus();
UpdatePassy();
}
function UpdatePassy()
{
// do password update
var site = document.getElementById('site').value;
var password = document.getElementById('password').value;
if ( site == "" || password == "" )
{
document.getElementById('result').value = "";
}
else
{
document.getElementById('result').value = passy(site,password)[0];
}
// set timer to clear password field after a minute
if ( password_timer != 0 )
{
clearTimeout(password_timer);
}
password_timer = setTimeout('ClearPassword()',60000);
}
</script>
</head>
<body>
<form>
Site Name:<br/>
<input type='text' id='site' onkeydown='UpdatePassy()' onkeyup='UpdatePassy()' onchange='UpdatePassy()'><br/>
Secret Passphrase:<br/>
<input type='password' id='password' onkeydown='UpdatePassy()' onkeyup='UpdatePassy()' onchange='UpdatePassy()'><br/>
<hr/>
Site Password:<br/>
<input type='text' id='result' readonly onfocus='this.select()' onclick='this.select()' ondblclick='this.select()'>
</form>
</body>
</html>
+9
View File
@@ -0,0 +1,9 @@
(function(){var q=function(a){var c=[],d=a.length*8,b;for(b=0;b<d;b+=8)c[b>>5]|=(a.charCodeAt(b/8)&255)<<24-b%32;return c},r=function(a){var c=[],d=a.length,b,e;for(b=0;b<d;b+=2){e=parseInt(a.substr(b,2),16);if(isNaN(e))return"INVALID HEX STRING";else c[b>>3]|=e<<24-4*(b%8)}return c},m=function(a){var c="",d=a.length*4,b,e;for(b=0;b<d;b+=1){e=a[b>>2]>>(3-b%4)*8;c+="0123456789abcdef".charAt(e>>4&15)+"0123456789abcdef".charAt(e&15)}return c},n=function(a){var c="",d=a.length*4,b,e,j;for(b=0;b<d;b+=
3){j=(a[b>>2]>>8*(3-b%4)&255)<<16|(a[b+1>>2]>>8*(3-(b+1)%4)&255)<<8|a[b+2>>2]>>8*(3-(b+2)%4)&255;for(e=0;e<4;e+=1)c+=b*8+e*6<=a.length*32?"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(j>>6*(3-e)&63):""}return c},f=function(a,c){return a<<c|a>>>32-c},o=function(a,c){var d=(a&65535)+(c&65535);return((a>>>16)+(c>>>16)+(d>>>16)&65535)<<16|d&65535},k=function(a,c,d,b,e){var j=(a&65535)+(c&65535)+(d&65535)+(b&65535)+(e&65535);return((a>>>16)+(c>>>16)+(d>>>16)+(b>>>16)+(e>>>16)+
(j>>>16)&65535)<<16|j&65535},u=function(a,c){var d=[],b,e,j,l,p,v,s,g,w,h=[1732584193,4023233417,2562383102,271733878,3285377520],t=[1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1518500249,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,
1859775393,1859775393,1859775393,1859775393,1859775393,1859775393,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,2400959708,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782,3395469782];
a[c>>5]|=128<<24-c%32;a[(c+65>>9<<4)+15]=c;w=a.length;for(s=0;s<w;s+=16){b=h[0];e=h[1];j=h[2];l=h[3];p=h[4];for(g=0;g<80;g+=1){d[g]=g<16?a[g+s]:f(d[g-3]^d[g-8]^d[g-14]^d[g-16],1);v=g<20?k(f(b,5),e&j^~e&l,p,t[g],d[g]):g<40?k(f(b,5),e^j^l,p,t[g],d[g]):g<60?k(f(b,5),e&j^e&l^j&l,p,t[g],d[g]):k(f(b,5),e^j^l,p,t[g],d[g]);p=l;l=j;j=f(e,30);e=b;b=v}h[0]=o(b,h[0]);h[1]=o(e,h[1]);h[2]=o(j,h[2]);h[3]=o(l,h[3]);h[4]=o(p,h[4])}return h},x=function(a,c){this.strToHash=this.strBinLen=this.sha1=null;if("HEX"===c){if(0!==
a.length%2)return"TEXT MUST BE IN BYTE INCREMENTS";this.strBinLen=a.length*4;this.strToHash=r(a)}else if("ASCII"===c||"undefined"===typeof c){this.strBinLen=a.length*8;this.strToHash=q(a)}else return"UNKNOWN TEXT INPUT TYPE"};x.prototype={getHash:function(a){var c=null,d=this.strToHash.slice();switch(a){case "HEX":c=m;break;case "B64":c=n;break;default:return"FORMAT NOT RECOGNIZED"}if(null===this.sha1)this.sha1=u(d,this.strBinLen);return c(this.sha1)},getHMAC:function(a,c,d){var b;b=[];var e=[];switch(d){case "HEX":d=
m;break;case "B64":d=n;break;default:return"FORMAT NOT RECOGNIZED"}if("HEX"===c){if(0!==a.length%2)return"KEY MUST BE IN BYTE INCREMENTS";c=r(a);a=a.length*4}else if("ASCII"===c){c=q(a);a=a.length*8}else return"UNKNOWN KEY INPUT TYPE";if(64<a/8){c=u(c,a);c[15]&=4294967040}else if(64>a/8)c[15]&=4294967040;for(a=0;a<=15;a+=1){b[a]=c[a]^909522486;e[a]=c[a]^1549556828}b=u(b.concat(this.strToHash),512+this.strBinLen);b=u(e.concat(b),672);return d(b)}};window.jsSHA=x})();
var passy=function(q,r){var m=function(f){var o={"1":"!","2":"@","3":"#","4":"$","5":"%","6":"^","7":"&","8":"*","9":"(","0":")"},k=true;for(i=0;i<f.length;++i)if(/[0-9]/.test(f[i])){if(k)f=f.slice(0,i)+o[f[i]]+f.slice(i+1,f.length);k=!k}k=true;for(i=0;i<f.length;++i)if(/[a-f]/i.test(f[i])){f=f.slice(0,i)+(k?f[i].toUpperCase():f[i].toLowerCase())+f.slice(i+1,f.length);k=!k}return f},n=(new jsSHA(q.toLowerCase(),"ASCII")).getHMAC(r,"ASCII","HEX");return[m(n.slice(0,10)),m(n.slice(10,20)),m(n.slice(20,
30)),m(n.slice(30,40))]};