Skip to content

Commit

Permalink
Merge pull request #70 from justinlatimer/update-bcrypt
Browse files Browse the repository at this point in the history
Update bcrypt
  • Loading branch information
bnoguchi committed Feb 3, 2012
2 parents 72e610f + 5ea5d80 commit e4c38fe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
7 changes: 2 additions & 5 deletions Makefile
@@ -1,7 +1,4 @@
test:
@expresso test/authplugin.test.js
@node_modules/.bin/mocha

test-cov:
@TESTFLAGS=--cov $(MAKE) test

.PHONY: test test-cov
.PHONY: test
4 changes: 2 additions & 2 deletions lib/modules/password/plugin.js
Expand Up @@ -36,8 +36,8 @@ exports = module.exports = function (schema, opts) {
return this._password;
}).set( function (password) {
this._password = password;
var salt = this.salt = bcrypt.gen_salt_sync(10);
this.hash = bcrypt.encrypt_sync(password, salt);
var salt = this.salt = bcrypt.genSaltSync(10);
this.hash = bcrypt.hashSync(password, salt);
});

schema.method('authenticate', function (password, callback) {
Expand Down
9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -13,14 +13,19 @@
"lib": "."
},
"dependencies": {
"bcrypt":">=0.2.0",
"bcrypt":">=0.5.0",
"mongoose": ">=1.4.0",
"everyauth": "0.2.23",
"mongoose-types": ">=1.0.3"
},
"devDependencies": {
"express": ">=2.3.2",
"jade": ">=0.12.1"
"jade": ">=0.12.1",
"mocha": ">=0.10.1",
"should": ">=0.5.1"
},
"scripts": {
"test": "make"
},
"engines": {
"node": ">=0.4.0"
Expand Down
28 changes: 16 additions & 12 deletions test/authplugin.test.js
Expand Up @@ -11,26 +11,30 @@ UserSchema.plugin(authPlugin, {
mongoose.model('User', UserSchema);
User = mongoose.model('User');

module.exports = {
"setting a user's password should generate a salt and set a hash": function () {
describe('User', function () {
it('should generate a salt and set a hash when password is set', function () {
var user = new User();
should.strictEqual(undefined, user.salt);
should.strictEqual(undefined, user.hash);
user.password = 'hello';
user.password.should.equal('hello');
user.salt.should.not.be.undefined;
user.hash.should.not.be.undefined;
},

'a user should authenticate with a correct password': function () {
});
it('should authenticate with a correct password', function (done) {
var user = new User();
user.password = 'hello';
user.authenticate('hello').should.be.true;
},

'a user should fail authentication with an incorrect password': function () {
user.authenticate('hello', function (err, matched) {
matched.should.be.true;
done();
});
});
it('should fail authentication with an incorrect password', function (done) {
var user = new User();
user.password = 'correct';
user.authenticate('incorrect').should.be.false;
}
};
user.authenticate('incorrect', function (err, matched) {
matched.should.be.false;
done();
});
});
});

0 comments on commit e4c38fe

Please sign in to comment.