Created
November 5, 2018 13:56
-
-
Save bikashthapa01/8b07ec60ccc6ccdd6057515242eb1fa4 to your computer and use it in GitHub Desktop.
Hash user Password before inserting into Database while Registering a user using bcrypt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// package used | |
var bcrypt = require('bcrypt-nodejs'); | |
bcrypt.hash(password, null, null, function(err, hash) { | |
// password -> raw password ( req.body.password) | |
// hash -> hashed password | |
// connect and insert to database | |
var db = require('../db'); // open connection to database | |
db.query('INSERT INTO user(username,password,is_student) VALUES(?,?,?)',[username,hash,is_student],function(err){ | |
if(err) throw err; | |
res.render('auth/register',{msg:'Registration Successfull'}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment