Bcrypt And PassportJs User Registration Bcrypt And PassportJs User Registration mongoose mongoose

Bcrypt And PassportJs User Registration


There are multiple methods to hash a password using bcrypt.js. Like you can use Promise, async, sync. The one that you used is async that generates salt and hash on a separate function calls. One error in your code is it should be password:req.body.password you need to use dot(.) after body instead of colon(:).

Besides your code one of the methods to hash a password is

 router.post('/kayıt', async (req, res) => {     //hashed password     const salt = await bcrypt.genSalt(10);    const hashedPassword = await bcrypt.hash(req.body.password, salt);    const user = new User({       isim: req.body.isim,       email: req.body.email,       password: hashedPassword    });    user.save(function(err) {             if (err) {                console.log(err);             } else {                res.redirect('/');               }             });         });

You can have a look here.