100xdevs-cohort-2 / paytm

144 stars 334 forks source link

Password hashing and salting is pending ! #7

Open Sanket00900 opened 5 months ago

Sanket00900 commented 5 months ago

Whenever we are creating new user, the user's password should be hased before saving to the database

vineet-op commented 4 months ago

Here https://youtu.be/m_8rwKsYmnY?si=M0ZJC8GbDNF2Z6j3

This might Help You

RevanthMali commented 3 months ago

I hope this might help you it's working, modify the code accordingly ,

IN db.js

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); }

IN user.js

var hashedPassword = await user.createHash(req.body.password); user.password = hashedPassword; await user.save();