Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Please help in deciding if this method for a Mongoose model component for user authentication can be made more secure and optimized, for efficiency and platform independence.

var mongo  = require('mongoose');
var bcrypt = require('bcrypt');

var UserSchema = mongo.Schema({
    email:      {type: String, lowercase: true, required: true, sparse: true, unique:true},
    firstname:  {type: String, required: true},
    lastname:   {type: String, required: true},
    password:   {type: String, required: true},
    type:       {type: String, required: true}
});

UserSchema.methods.generateHash = function(password) {
    return bcrypt.hashSync(password, bcrypt.genSaltSync(10));
};

UserSchema.methods.validPassword = function(password) { 
    return bcrypt.compareSync(password, this.password);
};

UserSchema.methods.getData = function(){
    return {
      id:         this._id,
      email:      this.email,
      firstname:  this.firstname,
      lastname:   this.lastname,
      type:       this.type
    };
};

module.exports = mongo.model('User', UserSchema);

My model uses some of the best practices when creating a secured user object, I believe.

share|improve this question
1  
Hm, on my windows machine bcrypt runs like a charm. The problem can be with building the source code in c++, but you can run into the problem not only with bcrypt but with other packages that need compiling –  Vsevolod Goloviznin Dec 30 '14 at 11:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.