Skip to content

Commit

Permalink
This adds 60 second caching of bcrypt compared to reduce the cpu time…
Browse files Browse the repository at this point in the history
… on session-less reset requests (openhab#62)

Signed-off-by: Dan Cunningham <[email protected]>
  • Loading branch information
digitaldan authored Mar 13, 2017
1 parent 79d5472 commit 27dc00f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 51 deletions.
11 changes: 10 additions & 1 deletion models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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 () {
Expand Down
100 changes: 50 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 27dc00f

Please sign in to comment.