diff --git a/models/user.js b/models/user.js index a37d5c2..b5c80f0 100644 --- a/models/user.js +++ b/models/user.js @@ -6,6 +6,13 @@ var mongoose = require('mongoose'), UserAccount = require('./useraccount'), ObjectId = mongoose.SchemaTypes.ObjectId; +var MemoryBcryptCache = require('bcrypt-cache').MemoryBcryptCache; +var memCache = new MemoryBcryptCache({ + ttl: 60, + pruneTimer: 60 +}); + + var UserSchema = new Schema({ username: {type: String, unique: true}, firstName: {type: String}, @@ -25,7 +32,9 @@ var UserSchema = new Schema({ /*userSchema.plugin(passportLocalMongoose);*/ UserSchema.method('checkPassword', function (password, callback) { - bcrypt.compare(password, this.hash, callback); + memCache.compare(this.hash,password).then(function (result) { + callback(null,result); + }); }); UserSchema.virtual('password').get(function () { diff --git a/package.json b/package.json index 56f8959..c52f517 100644 --- a/package.json +++ b/package.json @@ -1,52 +1,52 @@ { - "name": "openhabcloud", - "description": "openHAB cloud service main package", - "version": "0.0.2", - "private": true, - "scripts": { - "start": "node app.js" - }, - "dependencies": { - "express": "3.20.2", - "ejs": "2.5.5", - "less-middleware": "2.2.0", - "socket.io": "1.3.7", - "socket.io-client": "1.1.0", - "request": "2.16.6", - "mongoose": "4.4.8", - "mongoose-types": "1.0.3", - "passport": "0.1.18", - "passport-local": "1.0.0", - "bcrypt": "1.0.2", - "connect-mongodb": "1.1.5", - "redis": "2.6.2", - "hiredis": "0.4", - "ejs-locals": "1.0.2", - "express-form": "0.12.6", - "connect-flash": "0.1.1", - "chokidar": "0.6.2", - "uuid": "3.0.1", - "node-gcm": "0.14.4", - "winston": "0.7.2", - "nodemailer": "0.5.2", - "connect-redis": "3.1.0", - "email-templates": "2.5.4", - "moment": "2.3.1", - "timezone": "0.0.23", - "time": "0.11.4", - "node-xmpp": "1.0.8", - "cron": "1.0.3", - "apn": "1.7.6", - "oauth2orize": "1.0.1", - "passport-http": "0.2.2", - "passport-oauth2-client-password": "0.1.2", - "passport-http-bearer": "1.0.1", - "socket.io-redis": "0.1.4", - "memwatch-next": "0.3.0", - "heapdump": "0.3.7", - "mongoose-cache": "0.1.4", - "ratelimiter":"2.1.3", - "express-session":"1.14.1", - "heapdump":"0.3.7" - } + "name": "openhabcloud", + "description": "openHAB cloud service main package", + "version": "0.0.2", + "private": true, + "scripts": { + "start": "node app.js" + }, + "dependencies": { + "apn": "1.7.6", + "bcrypt": "1.0.2", + "bcrypt-cache": "^1.0.2", + "chokidar": "0.6.2", + "connect-flash": "0.1.1", + "connect-mongodb": "1.1.5", + "connect-redis": "3.1.0", + "cron": "1.0.3", + "ejs": "2.5.5", + "ejs-locals": "1.0.2", + "email-templates": "2.5.4", + "express": "3.20.2", + "express-form": "0.12.6", + "express-session": "1.14.1", + "heapdump": "0.3.7", + "hiredis": "0.4", + "less-middleware": "2.2.0", + "memwatch-next": "0.3.0", + "moment": "2.3.1", + "mongoose": "4.4.8", + "mongoose-cache": "0.1.4", + "mongoose-types": "1.0.3", + "node-gcm": "0.14.4", + "node-xmpp": "1.0.8", + "nodemailer": "0.5.2", + "oauth2orize": "1.0.1", + "passport": "0.1.18", + "passport-http": "0.2.2", + "passport-http-bearer": "1.0.1", + "passport-local": "1.0.0", + "passport-oauth2-client-password": "0.1.2", + "ratelimiter": "2.1.3", + "redis": "2.6.2", + "request": "2.16.6", + "socket.io": "1.3.7", + "socket.io-client": "1.1.0", + "socket.io-redis": "0.1.4", + "time": "0.11.4", + "timezone": "0.0.23", + "uuid": "3.0.1", + "winston": "0.7.2" + } }