0

I am trying to override loopback deafult password hashing i have previously posted in Stack but to no avail

How to override the default password hashing method and validation method of loopback?

I have this Java method

 public static String digest(String string, String salt) throws Exception {
    MessageDigest digest = MessageDigest.getInstance("SHA-256");
    digest.reset();
    digest.update(salt.getBytes("UTF-8"));

    byte[] btPass = digest.digest(string.getBytes("UTF-8"));
    int iter = 1000;
    for (int i = 0; i < iter; i++) {
        digest.reset();
        btPass = digest.digest(btPass);
    }
    HexBinaryAdapter adapter = new HexBinaryAdapter();
    return adapter.marshal(btPass);
}

How to use this same in Javascript Node js using jssha 1.6.0

I tried using this but the hash seems to be different for both methods can anyone help me on this

var shaObj = new jsSHA(plain + salt, 'TEXT');
//console.log('passphrase : text', text);
//console.log('passphrase : salt', salt);
//salt = salt || '';
//var shaObj = new jsSHA(salt + text + massiveSalt, 'TEXT');
console.log(shaObj.getHash('SHA-256', 'HEX'));

this.$password = plain;
console.log(plain);
INFOSYS
  • 1,465
  • 9
  • 23
  • 50

1 Answers1

0
        var shaObj = new jsSHA("salt"+plain, "BYTES");
        var hash = shaObj.getHash("SHA-256", "HEX");

        for (var i = 0; i < 1000; i++) {
            shaObj = new jsSHA(hash, "HEX");
            hash = shaObj.getHash("SHA-256", "HEX");
        }

        console.log(hash);

This should work

Rahul Singh
  • 19,030
  • 11
  • 64
  • 86