Created
April 4, 2011 23:30
-
-
Save jslatts/902705 to your computer and use it in GitHub Desktop.
Redis callback example
This file contains hidden or 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
exports.authenticateUserByHash = function(name, hash, fn) { | |
winston.info('[authenticateUserByHash] Starting hash auth for ' + name + ' with hash ' + hash); | |
var rKey = 'user:' + name; | |
rc.get(rKey, function(err, data){ | |
if(err) return fn(new Error('[authenticateUserByHash] GET failed for key: ' + rKey + ' for value: ' + name)); | |
if (!data) { | |
fn(new Error('[authenticateUserByHash] user: ' + name + ' not found in store.')); | |
} | |
else { | |
winston.info('[authenticateUserByHash] user: ' + name + ' found in store. Verifying password.'); | |
rc.get(rKey + '.hashPass', function(err, data) { | |
if(err) { | |
return fn(new Error('[authenticateUserByHash] GET failed for key: ' + rKey + ' for value: ' + name)); | |
} | |
if(!data) { | |
return fn(new Error('[authenticateUserByHash] hash did not much for user: ' + name)); | |
} | |
else { | |
winston.info('[authenticateUserByHash] user: ' + name + ' hash verified. Authenticated.'); | |
return fn(null, true); | |
} | |
}); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment