Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Replaced SHA1 password hashing with more bcrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
mrngoitall committed Sep 13, 2013
1 parent 612b014 commit 035dd2c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
18 changes: 3 additions & 15 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
crypto = require('crypto'),
bcrypt = require('bcrypt'),
_ = require('underscore'),
authTypes = ['github', 'twitter', 'facebook', 'google'];

Expand All @@ -17,7 +17,6 @@ var UserSchema = new Schema({
username: String,
provider: String,
hashed_password: String,
salt: String,
facebook: {},
twitter: {},
github: {},
Expand All @@ -29,7 +28,6 @@ var UserSchema = new Schema({
*/
UserSchema.virtual('password').set(function(password) {
this._password = password;
this.salt = this.makeSalt();
this.hashed_password = this.encryptPassword(password);
}).get(function() {
return this._password;
Expand Down Expand Up @@ -92,17 +90,7 @@ UserSchema.methods = {
* @api public
*/
authenticate: function(plainText) {
return this.encryptPassword(plainText) === this.hashed_password;
},

/**
* Make salt
*
* @return {String}
* @api public
*/
makeSalt: function() {
return Math.round((new Date().valueOf() * Math.random())) + '';
return bcrypt.compareSync(plainText,this.hashed_password);
},

/**
Expand All @@ -114,7 +102,7 @@ UserSchema.methods = {
*/
encryptPassword: function(password) {
if (!password) return '';
return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
return bcrypt.hashSync(password, 10);
}
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"forever": "latest",
"grunt": "latest",
"grunt-cli": "latest",
"grunt-bower-task": "latest"
"grunt-bower-task": "latest",
"bcrypt": "latest"
},
"devDependencies": {
"supertest": "latest",
Expand Down

0 comments on commit 035dd2c

Please sign in to comment.