mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-04 14:29:05 +02:00
Revert "Merge pull request #79 from mrngoitall/master"
This reverts commitb83fb4a4c9, reversing changes made tof5f4663774.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
var mongoose = require('mongoose'),
|
||||
Schema = mongoose.Schema,
|
||||
bcrypt = require('bcrypt'),
|
||||
crypto = require('crypto'),
|
||||
_ = require('underscore'),
|
||||
authTypes = ['github', 'twitter', 'facebook', 'google'];
|
||||
|
||||
@@ -17,6 +17,7 @@ var UserSchema = new Schema({
|
||||
username: String,
|
||||
provider: String,
|
||||
hashed_password: String,
|
||||
salt: String,
|
||||
facebook: {},
|
||||
twitter: {},
|
||||
github: {},
|
||||
@@ -28,6 +29,7 @@ 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;
|
||||
@@ -90,7 +92,17 @@ UserSchema.methods = {
|
||||
* @api public
|
||||
*/
|
||||
authenticate: function(plainText) {
|
||||
return bcrypt.compareSync(plainText,this.hashed_password);
|
||||
return this.encryptPassword(plainText) === this.hashed_password;
|
||||
},
|
||||
|
||||
/**
|
||||
* Make salt
|
||||
*
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
makeSalt: function() {
|
||||
return Math.round((new Date().valueOf() * Math.random())) + '';
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -102,7 +114,7 @@ UserSchema.methods = {
|
||||
*/
|
||||
encryptPassword: function(password) {
|
||||
if (!password) return '';
|
||||
return bcrypt.hashSync(password, 10);
|
||||
return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -36,8 +36,7 @@
|
||||
"forever": "latest",
|
||||
"grunt": "latest",
|
||||
"grunt-cli": "latest",
|
||||
"grunt-bower-task": "latest",
|
||||
"bcrypt": "latest"
|
||||
"grunt-bower-task": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"supertest": "latest",
|
||||
|
||||
Reference in New Issue
Block a user