Skip to content

Instantly share code, notes, and snippets.

View FrancescaK's full-sized avatar

Francesca Krihely FrancescaK

View GitHub Profile
@FrancescaK
FrancescaK / gist:3832812
Created October 4, 2012 10:32
testing passwords
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:3832833
Created October 4, 2012 10:34
Password Testing Scenario
var mongoose = require(‘mongoose’),
Schema = mongoose.Schema,
bcrypt = require(‘bcrypt’),
SALT_WORK_FACTOR = 10;
var UserSchema = new Schema({
username: { type: String, required: true, index: { unique: true } },
password: { type: String, required: true }
});
@FrancescaK
FrancescaK / gist:3832839
Created October 4, 2012 10:35
comparing passwords
UserSchema.methods.comparePassword = function(candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, function(err, isMatch) {
if (err) return cb(err);
cb(null, isMatch);
});
@FrancescaK
FrancescaK / gist:3832874
Created October 4, 2012 10:38
hash the password
UserSchema.pre(‘save’, { var user = this;
// only hash the password if it has been modified (or is new)
if (!user.isModified('password')) return next();
// generate a salt
bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) {
if (err) return next(err);
// hash the password along with our new salt
bcrypt.hash(user.password, salt, function(err, hash) {
@FrancescaK
FrancescaK / gist:3832893
Created October 4, 2012 10:41
require:mongoose
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
bcrypt = require(bcrypt),
SALT_WORK_FACTOR = 10;
var UserSchema = new Schema({
username: { type: String, required: true, index: { unique: true } },
password: { type: String, required: true }
});
@FrancescaK
FrancescaK / gist:3859204
Created October 9, 2012 14:32
mongodb notebook openshift
{ "name" : "MongoDB Notebook", "description" : "My MongoDB Notes", "created" : ISODate("2012-09-25T12:22:23.590Z"), "author" : "test_user", "tags" : [ "mongodb", "nosql" ], "notes" : [ { "title" : "Say hello to MongoDB", "text" : "Say hello to MongoDB", "created" : ISODate("2012-09-25T12:22:23.593Z"), "tags" : [ "mongodb", "getting-started" ] }, { "title" : "How to setup ReplicaSet in MongoDB", "text" : "How to setup ReplicaSet in MongoDB", "created" : ISODate("2012-09-25T12:22:23.593Z"), "tags" : [ "mongodb", "replication" ] } ] }
@FrancescaK
FrancescaK / gist:3859493
Created October 9, 2012 15:23
rhc client cardridge
rhc app cartridge add -a notebook -c mongodb-2.0 rhc app cartridge add -a notebook -c rockmongo-1.1
@FrancescaK
FrancescaK / gist:3859510
Created October 9, 2012 15:25
git add for OpenShift post
git add . git commit -a -m "maven multi module project structure created" git push
@FrancescaK
FrancescaK / gist:3859516
Created October 9, 2012 15:26
brevity notebooks
@Document(collection = “notebooks”) public class Notebook {
@Id private String id; private String name; private String description; @DateTimeFormat(style = "M-") private Date created = new Date(); private String author; private String[] tags; private Note[] notes;
@FrancescaK
FrancescaK / gist:3945190
Created October 24, 2012 09:47
Mongoose User Model
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
bcrypt = require('bcrypt'),
SALT_WORK_FACTOR = 10;
var UserSchema = new Schema({
username: { type: String, required: true, index: { unique: true } },
password: { type: String, required: true }
});