Skip to content

Instantly share code, notes, and snippets.

@sipple
Created July 11, 2011 15:47
Show Gist options
  • Save sipple/1076133 to your computer and use it in GitHub Desktop.
Save sipple/1076133 to your computer and use it in GitHub Desktop.
Hash This
function checkCredentials() {
// Set user action to Authenticate
document.UserForm.useraction.value = 'login';
if (document.UserForm.url.value == '') {
alert('Please enter the authenticatin url');
return false;
}
if (document.UserForm.username.value == '' || document.UserForm.password.value == '') {
alert('Please enter credentials');
return false;
}
// Hash password with username and random number and submit the form
document.UserForm.password.value = coverPass(document.UserForm.password.value, document.UserForm.username.value);
var rand = String(Math.random()).substr(2, 16);
document.UserForm.random.value = rand;
document.UserForm.password.value = coverPass(document.UserForm.password.value, rand);
document.UserForm.submit();
return true;
}
function sendXml() {
// Set user action to Web Request
document.UserForm.useraction.value = 'xmlrequest';
// Validate request fields
if (document.UserForm.requestxml.value == '') {
alert('Please enter some request XML');
return false;
}
if (document.UserForm.requesturl.value == '') {
alert('Please enter a request Url');
return false;
}
if (document.UserForm.webmethodname.value == '') {
alert('Please enter a web method name');
return false;
}
if (document.UserForm.webservicename.value == '') {
alert('Please enter a web service name');
return false;
}
// All ok, submit form
document.UserForm.submit();
return true;
}
function coverPass(thePass, theName) {
thePass += theName; // concat the password and name to get more unique
var a = 0x67452301;
var b = 0xEFCDAB89;
var c = 0x98BADCFE;
var d = 0x10325476;
var e = 0xC3D2E1F0;
var w = new Array(80);
var nblk = ((thePass.length + 8) >> 6) + 1;
var x = new Array(nblk * 16);
var i = 0;
var j = 0;
for (i = 0; i < (nblk * 16); i++) {
x[i] = 0;
}
for (i = 0; i < thePass.length; i++) {
x[i >> 2] |= thePass.charCodeAt(i) << (24 - (i % 4) * 8);
}
x[i >> 2] |= 0x80 << (24 - (i % 4) * 8);
x[nblk * 16 - 1] = thePass.length * 8;
for (i = 0; i < x.length; i += 16) {
oldA = a;
oldB = b;
oldC = c;
oldD = d;
oldE = e;
for (j = 0; j < 80; j++) {
if (j < 16) w[j] = x[i + j];
else w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
t = sum32(sum32(rol(a, 5), ft(j, b, c, d)), sum32(sum32(e, w[j]), kt(j)));
e = d;
d = c;
c = rol(b, 30);
b = a;
a = t;
}
a = sum32(a, oldA);
b = sum32(b, oldB);
c = sum32(c, oldC);
d = sum32(d, oldD);
e = sum32(e, oldE);
}
return numToHex(a) + numToHex(b) + numToHex(c) + numToHex(d) + numToHex(e);
}
function numToHex(num) { // convert to a hex string
hexStr = "";
for (var i = 7; i >= 0; i--) {
hexStr += "0123456789abcdef".charAt((num >> (i * 4)) & 0x0F);
}
return hexStr;
}
function ft(t, b, c, d) {
if (t < 20) return (b & c) | ((~b) & d);
if (t < 40) return b ^ c ^ d;
if (t < 60) return (b & c) | (b & d) | (c & d);
return (b ^ c ^ d);
}
function kt(t) {
if (t < 20) {
return (0x5A827999);
}
if (t < 40) {
return (0x6ED9EBA1);
}
if (t < 60) {
return (0x8F1BBCDC);
}
return (0xCA62C1D6);
}
function sum32(x, y) {
return ((x & 0x7FFFFFFF) + (y & 0x7FFFFFFF)) ^ (x & 0x80000000) ^ (y & 0x80000000);
}
function rol(theNum, cnt) {
return (theNum << cnt) | (theNum >>> (32 - cnt));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment