bcrypt password hashing code example
Example 1: bcrypt compare hash and password
var bcrypt = dcodeIO.bcrypt;
var salt = bcrypt.genSaltSync(10);
bcrypt.hash('anypassword', salt, (err, res) => {
console.log('hash', res)
hash = res
compare(hash)
});
function compare(encrypted) {
bcrypt.compare('aboveusedpassword', encrypted, (err, res) => {
console.log('Compared result', res, hash)
})
}
Example 2: bcrypt Password Hashing
BCrypt.with(BCrypt.Version.VERSION_2Y).hashToChar(10, password.toCharArray());
Example 3: bcrypt
>>> import bcrypt
>>> password = b"super secret password"
>>> # Hash a password for the first time, with a randomly-generated salt
>>> hashed = bcrypt.hashpw(password, bcrypt.gensalt())
>>> # Check that an unhashed password matches one that has previously been
>>> # hashed
>>> if bcrypt.checkpw(password, hashed):
... print("It Matches!")
... else:
... print("It Does not Match :(")