Skip to content

Instantly share code, notes, and snippets.

@bikashthapa01
Created November 5, 2018 13:56
Show Gist options
  • Save bikashthapa01/8b07ec60ccc6ccdd6057515242eb1fa4 to your computer and use it in GitHub Desktop.
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
// 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