Skip to content

Instantly share code, notes, and snippets.

@CodingFu
Created November 13, 2013 00:08
Show Gist options
  • Save CodingFu/7441132 to your computer and use it in GitHub Desktop.
Save CodingFu/7441132 to your computer and use it in GitHub Desktop.
Simple devise user login check in node.js
var mysql = require('mysql')
, bcrypt = require('bcrypt')
, db = {
host: 'localhost',
user: 'root',
database: 'prod'
};
function checkUser(email, password, callback) {
var connection = mysql.createConnection(db);
connection.query('SELECT encrypted_password FROM users WHERE email = ? LIMIT 1', [email], function(err, results) {
if (err || results.length == 0) { callback(false); return; }
var encrypted_password = results[0]["encrypted_password"];
bcrypt.compare(password, encrypted_password, function(err, res) {
if (err) { callback(false); return; }
callback(!!res);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment