Skip to content

Commit

Permalink
Update user.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Sevilleja committed Jan 2, 2014
1 parent 3ff2322 commit 801020c
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions app/models/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// app/models/user.js
// load the things we need
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');
Expand Down Expand Up @@ -31,24 +30,14 @@ var userSchema = mongoose.Schema({

});

// checking if password is valid using bcrypt
userSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
// generating a hash
userSchema.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};


// this method hashes the password and sets the users password
userSchema.methods.hashPassword = function(password) {
var user = this;

// hash the password
bcrypt.hash(password, null, null, function(err, hash) {
if (err)
return next(err);

user.local.password = hash;
});

// checking if password is valid
userSchema.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
};

// create the model for users and expose it to our app
Expand Down

0 comments on commit 801020c

Please sign in to comment.