javascript - Trying to store hashed username in database -


i trying hash username using javascript-md5 plugin, , store database use jdenticon. able hash password , log console using var hash = md5($scope.username); unable pass newuser variable.

  1. registration controller

    $scope.register = function(){ var hash = md5($scope.username); console.log(hash); var newuser = {   email: $scope.email,   password: $scope.password,   username: $scope.username,   userhash: hash };  $http.post('/users/register', newuser).then(function(){   $scope.email = '';   $scope.password = '';   $scope.username = '';   userhash = ''; }; 
  2. registration route:

    app.post('/users/register', function(req, res) {    bcrypt.gensalt(10, function(err, salt) {     bcrypt.hash(req.body.password, salt, function(err, hash) {       var user = new user({         email: req.body.email,         password: hash,         username: req.body.username,         userhash: req.body.userhash       });       console.log(user);        user.save(function(err) {          if (err) return res.send(err);           return res.send();       });     });   }); }); 

i guess may missed userhash property in user model that's why can't store userhash in database.

so should include first userhash in user model should working fine.

like:

var mongoose = require('mongoose'),     schema = mongoose.schema;  var userschema= new schema({     username : {         type: string,         required: true     },     email: {         type: string     },     password: {         type: string     },     userhash:{         type: string     } }); mongoose.model('user', userschema); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -