-
Notifications
You must be signed in to change notification settings - Fork 4
Bycrypt
##Description
This API or package is used to protect the password to be stored in Database. It uses hash functions to encrypt and to decrypt It incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function.
npm install bcrypt
var bcrypt = require('bcrypt'); const saltRounds = 10; const myPlaintextPassword = 's0//\P4$$w0rD'; const someOtherPlaintextPassword = 'not_bacon';
This bycrypt API is used in our project in order to store the passwords in Mongo DB during sign up and reset password API calls
/users/signup In order to compute hash and use salt function and encrypt the password /users/reset/:token In order to accept the new password and encrypt it
#####/users/signup bcrypt.genSalt(10, function (err, salt) { bcrypt.hash(password, salt, function (err, hash) {
db.collection('users')
.update({ _id: tokenInfo.userId }, { $set: { password: hash } })
.then((success) => {
db.collection('token').remove({ userId: tokenInfo.userId });
res.render('response');
})
####/users/reset/:token var salt = bcrypt.genSaltSync(10); newUser.password = bcrypt.hashSync(newUser.password, salt);
More information can be obtained from https://www.npmjs.com/package/bcrypt