Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Last active August 29, 2015 14:26
Show Gist options
  • Save gartenfeld/c5459752352a424a6ff4 to your computer and use it in GitHub Desktop.
Save gartenfeld/c5459752352a424a6ff4 to your computer and use it in GitHub Desktop.
Passport authentication using basic credentials.
passport.use(new LocalStrategy( // a new Local instance
function(username, password, done) { // passing in a function
User.findOne({ username: username }, function (err, user) { // Mongo interface
if (err) { return done(err); } // generic error
if (!user) { return done(null, false); } // user not found
if (!user.verifyPassword(password)) { return done(null, false); } // wrong password
return done(null, user); // authenticated, returns 'user'
});
}
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment