From af20c3ab6fd63e41475175e333810d09b3e9c3ea Mon Sep 17 00:00:00 2001 From: Tyler Henkel Date: Thu, 16 Jan 2014 13:23:02 -0500 Subject: [PATCH] fix(app): replaced bcrypt with crpyto for windows users fixes #55 --- templates/common/_package.json | 3 +-- templates/express/models/user.js | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/common/_package.json b/templates/common/_package.json index 959ce687f..4634b3a2b 100644 --- a/templates/common/_package.json +++ b/templates/common/_package.json @@ -8,8 +8,7 @@ "mongoose-unique-validator": "~0.3.0", "connect-mongo": "~0.4.0", "passport": "latest", - "passport-local": "latest", - "bcrypt": "~0.7.7"<% } %><% if (jade) { %>, + "passport-local": "latest"<% } %><% if (jade) { %>, "jade": "latest"<% } %><% if (!jade) { %>, "ejs": "~0.8.4"<% } %> }, diff --git a/templates/express/models/user.js b/templates/express/models/user.js index 307b710e9..1e22c0c3f 100644 --- a/templates/express/models/user.js +++ b/templates/express/models/user.js @@ -3,7 +3,7 @@ var mongoose = require('mongoose'), uniqueValidator = require('mongoose-unique-validator'), Schema = mongoose.Schema, - bcrypt = require('bcrypt'); + crypto = require('crypto'); var authTypes = ['github', 'twitter', 'facebook', 'google'], SALT_WORK_FACTOR = 10; @@ -130,7 +130,7 @@ UserSchema.methods = { * @api public */ makeSalt: function() { - return bcrypt.genSaltSync(SALT_WORK_FACTOR); + return crypto.randomBytes(16).toString('base64'); }, /** @@ -141,8 +141,9 @@ UserSchema.methods = { * @api public */ encryptPassword: function(password, salt) { - // hash the password using our new salt - return bcrypt.hashSync(password, salt); + if (!password || !this.salt) return ''; + var salt = new Buffer(this.salt, 'base64'); + return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64'); } };