Last active
August 29, 2015 14:23
-
-
Save bookercodes/00312f7e70eb884848b1 to your computer and use it in GitHub Desktop.
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
var crypto = require("crypto"); | |
module.exports = (function(){ | |
var DELIMITER = ":"; | |
function signToken(token) { | |
return crypto | |
.createHmac("sha1", "ZvACQyRwbh5zXTD8ta0W") | |
.update(token) | |
.digest("hex"); | |
} | |
function generateToken(user) { | |
var token = signToken(user.email + user.lastLogin + user.salt); | |
return token; | |
} | |
function checkToken(user, token) { | |
var expected = signToken(user.email + user.lastLogin + user.salt); | |
return token === expected; | |
} | |
return { | |
generateToken: generateToken, | |
checkToken: checkToken | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment