var ALG_PLAIN = 0; var ALG_CRYPT = 1; var ALG_APMD5 = 2; var ALG_APSHA = 3; var AP_SHA1PW_ID = "{SHA}"; var AP_MD5PW_ID = "$apr1$"; var itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; function ap_to64(v, n) { var s = ''; while (--n >= 0) { s += itoa64.charAt(v & 0x3f); v >>>= 6 } return s } function stringToArray(s) { var a = []; for (var i = 0; i < s.length; i++) a.push(s.charCodeAt(i)); return a } function htpasswd(a, b, c) { var d = ap_to64(Math.floor(Math.random() * 16777215), 4) + ap_to64(Math.floor(Math.random() * 16777215), 4); var e = 0; for (var i = 0; i < a.length; i++) if (a.charCodeAt(i) > 127) e++; if (e) alert("Apache doesn't like non-ascii characters in the user name."); var f = ''; switch (c) { case ALG_APSHA: f = AP_SHA1PW_ID + b64_sha1(b); break; case ALG_APMD5: var g = b; g += AP_MD5PW_ID; g += d; var h = str_md5(b + d + b); for (var j = b.length; j > 0; j -= 16) g += h.substr(0, (j > 16) ? 16 : j); for (i = b.length; i != 0; i >>= 1) if (i & 1) g += String.fromCharCode(0); else g += b.charAt(0); h = str_md5(g); var k; for (i = 0; i < 1000; i++) { k = ''; if (i & 1) k += b; else k += h.substr(0, 16); if (i % 3) k += d; if (i % 7) k += b; if (i & 1) k += h.substr(0, 16); else k += b; h = str_md5(k) } h = stringToArray(h); f = AP_MD5PW_ID + d + '$'; f += ap_to64((h[0] << 16) | (h[6] << 8) | h[12], 4); f += ap_to64((h[1] << 16) | (h[7] << 8) | h[13], 4); f += ap_to64((h[2] << 16) | (h[8] << 8) | h[14], 4); f += ap_to64((h[3] << 16) | (h[9] << 8) | h[15], 4); f += ap_to64((h[4] << 16) | (h[10] << 8) | h[5], 4); f += ap_to64(h[11], 2); break; case ALG_PLAIN: f = b; break; case ALG_CRYPT: default: f = Javacrypt.displayPassword(b, d); break } if (a.length + 1 + f.length > 255) alert('Your login and password are too long.'); else return a + ':' + f } function pwgen(a) { var b = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-@+_()[]{}=%*!§"; var c = ''; for (var i = 1; i <= a; i++) { c += b.substr(Math.floor(Math.random() * b.length), 1) } return c } function generation(f) { var a = pwgen(f.taille.options[f.taille.selectedIndex].text); f.pwd1.value = a; f.pwd2.value = htpasswd(f.user.value, a, f.alg.selectedIndex) } function gen() { document.getElementById('result').value = htpasswd(document.getElementById('user').value, document.getElementById('pwd1').value, +document.getElementById('alg').value) }