Skip to content

Instantly share code, notes, and snippets.

@dallas-x
Created May 23, 2017 22:46
Show Gist options
  • Save dallas-x/5a3719c16400689efe02527b73d4fa27 to your computer and use it in GitHub Desktop.
Save dallas-x/5a3719c16400689efe02527b73d4fa27 to your computer and use it in GitHub Desktop.
does this look sloppy?
var passport = require('passport'),
LocalStrategy = require('passport-local').Strategy,
sql = require('mssql');
module.exports = function () {
passport.use(new LocalStrategy({
usernameField:'userName',
passwordField:'password'
},
function(username, password, done) {
var ps = new sql.PreparedStatement();
ps.input('username', sql.VarChar(128));
ps.input('password', sql.VarChar(128));
ps.prepare('SELECT * FROM users WHERE username=@username AND userpassword=@password',
err => {
ps.execute({username:username, password:password},
function(err, recordset) {
if (err) {
console.log('sorry we could not process this request \n' + err);
}
else {
console.log(recordset.recordset);
if (recordset.recordset <= 0) {
console.log('no users found');
}
else {
var user = recordset.recordset[0];
if (user.userPassword === password) {
console.log('password matches');
done(null, user);
}
else {
console.log('password mismatch');
done(null, false);
}
}
}
});
});
}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment