Skip to content

Instantly share code, notes, and snippets.

View FrancescaK's full-sized avatar

Francesca Krihely FrancescaK

View GitHub Profile
@FrancescaK
FrancescaK / gist:3945206
Created October 24, 2012 09:49
Keeping Track of Failed Login Attempts and Account Locks
var UserSchema = new Schema({
// existing properties
username: { type: String, required: true, index: { unique: true } },
password: { type: String, required: true },
// new properties
loginAttempts: { type: Number, required: true, default: 0 },
lockUntil: { type: Number }
});
@FrancescaK
FrancescaK / gist:3945334
Created October 24, 2012 10:18
Defining Failed Login Reasons
// expose enum on the model
UserSchema.statics.failedLogin = {
NOT_FOUND: 0,
PASSWORD_INCORRECT: 1,
MAX_ATTEMPTS: 2
};
@FrancescaK
FrancescaK / gist:3945341
Created October 24, 2012 10:20
Encapsulating the Login Process
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
bcrypt = require('bcrypt'),
SALT_WORK_FACTOR = 10,
// these values can be whatever you want - we're defaulting to a
// max of 5 attempts, resulting in a 2 hour lock
MAX_LOGIN_ATTEMPTS = 5,
LOCK_TIME = 2 * 60 * 60 * 1000;
var UserSchema = new Schema({
@FrancescaK
FrancescaK / gist:3945349
Created October 24, 2012 10:21
sample usage
var mongoose = require('mongoose'),
User = require('./user-model');
var connStr = 'mongodb://localhost:27017/mongoose-bcrypt-test';
mongoose.connect(connStr, function(err) {
if (err) throw err;
console.log('Successfully connected to MongoDB');
});
// create a user a new user
@FrancescaK
FrancescaK / gist:4018756
Created November 5, 2012 17:35
unpack the download
config.cfg
precog.sh
precog.bat
@FrancescaK
FrancescaK / gist:4019355
Created November 5, 2012 18:07
configure precog
queryExecutor {
mongo {
server = "mongodb://localhost:27017"
}
}
@FrancescaK
FrancescaK / gist:4019382
Created November 5, 2012 18:12
config.cfg
security {
masterAccount {
apiKey = "12345678-1234-1234-1234-123456789abc"
}
}
@FrancescaK
FrancescaK / gist:4028164
Created November 6, 2012 22:41
port server
server {
port = 8888
}
...
labcoat {
port = 8000
}
@FrancescaK
FrancescaK / gist:4028198
Created November 6, 2012 22:48
port server
server {
port = 8888
}
...
labcoat {
port = 8000
}
#inserting documents
t.save( { _id: 1, title: "Physics World", text: "Physics World is the
membership magazine of the Institute of Physics."} );
t.save( { _id: 2, title: "A break away!", text: "'A break away!' is an
1891 painting by Australian artist Tom Roberts."} );
t.save( { _id: 3, title: "Mahim Bora", text: "Mahim Bora (b.1926) is an
Indian writer and educationist from Assam state."});