Open Sanket00900 opened 5 months ago
Here https://youtu.be/m_8rwKsYmnY?si=M0ZJC8GbDNF2Z6j3
This might Help You
I hope this might help you it's working, modify the code accordingly ,
userSchema.methods.createHash = async function(plainTextPassword){ const saltRounds = 10; const salt = await bcrypt.genSalt(saltRounds); return await bcrypt.hash(plainTextPassword,salt) } userSchema.methods.validatePassword= async function(candidatePassword){ return await bcrypt.compare(candidatePassword,this.password_hash); }
var hashedPassword = await user.createHash(req.body.password); user.password = hashedPassword; await user.save();
Whenever we are creating new user, the user's password should be hased before saving to the database