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

Commit a23f46f

Browse files
committed
Revert "Merge pull request #79 from mrngoitall/master"
This reverts commit b83fb4a, reversing changes made to f5f4663.
1 parent b83fb4a commit a23f46f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

app/models/user.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
var mongoose = require('mongoose'),
55
Schema = mongoose.Schema,
6-
bcrypt = require('bcrypt'),
6+
crypto = require('crypto'),
77
_ = require('underscore'),
88
authTypes = ['github', 'twitter', 'facebook', 'google'];
99

@@ -17,6 +17,7 @@ var UserSchema = new Schema({
1717
username: String,
1818
provider: String,
1919
hashed_password: String,
20+
salt: String,
2021
facebook: {},
2122
twitter: {},
2223
github: {},
@@ -28,6 +29,7 @@ var UserSchema = new Schema({
2829
*/
2930
UserSchema.virtual('password').set(function(password) {
3031
this._password = password;
32+
this.salt = this.makeSalt();
3133
this.hashed_password = this.encryptPassword(password);
3234
}).get(function() {
3335
return this._password;
@@ -90,7 +92,17 @@ UserSchema.methods = {
9092
* @api public
9193
*/
9294
authenticate: function(plainText) {
93-
return bcrypt.compareSync(plainText,this.hashed_password);
95+
return this.encryptPassword(plainText) === this.hashed_password;
96+
},
97+
98+
/**
99+
* Make salt
100+
*
101+
* @return {String}
102+
* @api public
103+
*/
104+
makeSalt: function() {
105+
return Math.round((new Date().valueOf() * Math.random())) + '';
94106
},
95107

96108
/**
@@ -102,7 +114,7 @@ UserSchema.methods = {
102114
*/
103115
encryptPassword: function(password) {
104116
if (!password) return '';
105-
return bcrypt.hashSync(password, 10);
117+
return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
106118
}
107119
};
108120

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
"forever": "latest",
3737
"grunt": "latest",
3838
"grunt-cli": "latest",
39-
"grunt-bower-task": "latest",
40-
"bcrypt": "latest"
39+
"grunt-bower-task": "latest"
4140
},
4241
"devDependencies": {
4342
"supertest": "latest",

0 commit comments

Comments
 (0)