-1

I wouldlike to hashing a password like symfony2, but in javascript. This is my code in Javascript :

this.hashPassword = function(salt, clearPassword) {

    var digest = "";
    console.log('==== STARTING HASHING PASSWORD ====');
    var salted = null;
    if (!salt || salt == "") {
      salted = clearPassword;
    } else {
      salted = clearPassword + "{" + salt + "}";
    }

    digest = CryptoJS.SHA512(salted);
    for (var i=1; i<5000; i++) {
      digest = CryptoJS.SHA512(digest.toString(CryptoJS.enc.Latin1)+salted);
    }
    digest = digest.toString(CryptoJS.enc.Base64);
    console.log('==== ENDING HASHING PASSWORD ====');
    console.log(digest);
    return digest;
};

The hash password i obtain isn't the same in the database, i don't really know why. My password in Symfony2 is hashed in SHA512 with a salt, i'm sure, because i test a code in PHP and it works.

Can you help me please ?

Thank you

1 Answers1

0

According to this answer is

SHA1 [..] not made for security [..] grab any implementation of BCrypt 

but there is an explanation that maybe a line break causes the different hashes. This can be turned off with Base64.encodeToString(byteData, Base64.NO_WRAP) in their case.

Community
  • 1
  • 1
tobi6
  • 8,033
  • 6
  • 26
  • 41