bcryptjs
npm i bcryptjs
# yarn
yarn add bcryptjs
bcrypt
// npm bcrypt used salt
// code
const bcrypt = require('bcrypt');
// hashing password.(registration)
const hashedPassword = await bcrypt.hash(req.body.password,10);
const user = { name: req.body.username, password: hashedPassword }
// compare password (login)
try {
if (await bcrypt.compare(password, user.password)) {
console.log("login successfull");
} else {
console.log("login failed");
}
} catch (e) {
console.log("something went wrong", error);
}
re.send(user)
bcrypt documentation
bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) {
// Store hash in your password DB.
});
bcrypt
const salt = bcrypt.genSaltSync(saltRounds);
const hash = bcrypt.hashSync(myPlaintextPassword, salt);
// Store hash in your password DB.
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 :(")
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us