Skip to content

Instantly share code, notes, and snippets.

@mountainpenguin
Created May 17, 2012 00:09
Show Gist options
  • Select an option

  • Save mountainpenguin/2715068 to your computer and use it in GitHub Desktop.

Select an option

Save mountainpenguin/2715068 to your computer and use it in GitHub Desktop.
my hash function
function getToken() {
return Math.floor( (new Date().getTime() / 1000) / 10 );
}
function genSalt() {
var salt = new String();
for (i=0; i<10; i++) {
var r = Math.floor( Math.random() * 128 );
salt += String.fromCharCode(r);
}
return salt;
}
function hashPassword(pw) {
var new_salt = genSalt();
var token = getToken();
var token_salt = CryptoJS.SHA256(token + new_salt);
var hashed1 = CryptoJS.SHA256(pw);
var hashed2 = CryptoJS.SHA256(pw + token_salt);
return "$" + new_salt + "$" + hashed2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment