Created
November 13, 2013 00:08
-
-
Save CodingFu/7441132 to your computer and use it in GitHub Desktop.
Simple devise user login check in node.js
This file contains 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 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