Skip to content

Instantly share code, notes, and snippets.

@jslatts
Created April 4, 2011 23:30
Show Gist options
  • Save jslatts/902705 to your computer and use it in GitHub Desktop.
Save jslatts/902705 to your computer and use it in GitHub Desktop.
Redis callback example
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