Created
February 28, 2018 21:27
-
-
Save arekgotfryd/a6d772df46300c86350e89b9804993ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
var testUser = new User({ | |
username: jmar777, | |
password: Password; | |
}); | |
// save user to database | |
testUser.save(function(err) { | |
if (err) throw err; | |
// fetch user and test password verification | |
User.findOne({ username: 'jmar777' }, function(err, user) { | |
if (err) throw err; | |
// test a matching password | |
user.comparePassword('Password', function(err, isMatch) { | |
if (err) throw err; | |
console.log('Password:', isMatch); // -> Password: true | |
}); | |
// test a failing password | |
user.comparePassword('123Password', function(err, isMatch) { | |
if (err) throw err; | |
console.log('123Password:', isMatch); // -> 123Password: false | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment