Skip to content

Instantly share code, notes, and snippets.

@rlemon
Created March 26, 2014 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlemon/9790295 to your computer and use it in GitHub Desktop.
Save rlemon/9790295 to your computer and use it in GitHub Desktop.
var passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
passwordHash = require('password-hash'),
pg = require('pg').native;
var connString = '';
var pgsql = new pg.Client(connString);
passport.use(new LocalStrategy(
function(providedUsername, password, done) {
pgsql.query('SELECT * FROM users WHERE username = ?', [providedUsername], function(err, res) {
var user = res[0];
if( !user ) {
return done(null, false, {message: 'incorrect username'});
}
if( !passwordHash.verify( password, user.password ) ) {
return done(null, false, {message: 'incorrect password'});
}
return done(null, user);
})
}
));
module.exports = ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment