简体   繁体   中英

Hash password in JS

I'm creating a web application that requires an authentication process. Saddly, I can't use HTTPS, so I'm stuck with the insecure HTTP. Currently, I'm sending passwords in plain text through HTTP... I know it's bad (even with HTTPS)! That's why I search a way to hash the password in JS, and send the hash to the server. Do you guys have any idea how i could do that ? (using the same blowfish implementation as PHP would be the best solution according to my needs)

Thanks !

edit : I know that anybody that could intercept the string could connect, but they couldn't know the password, only the hash.

    String.prototype.hashCode = function(){
    var hash = 0;
    if (this.length == 0) return hash;
    for (i = 0; i < this.length; i++) {
        char = this.charCodeAt(i);
        hash = ((hash<<5)-hash)+char;
        hash = hash & hash; // Convert to 32bit integer
    }
    return hash;
}

This is the method you can use to hash your password in JS

Courtesy : http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM