author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Thu, 25 Sep 2014 00:28:53 +0100 | |
changeset 176 | 5336ad2fd3fa |
parent 166 | bba0504abcf0 |
permissions | -rw-r--r-- |
var salt = 'secret key' function mk_hash(s) { return crypto.createHash('sha1').update(s).digest('hex') } function mk_cookie(c) { return c.toString() + '-' + mk_hash(c.toString() + salt) } function gt_cookie(s) { var splits = s.split("-", 2); var counter = parseInt(splits[0]) var hash = splits[1] if (mk_hash(counter.toString() + salt) == hash) { return counter } else { return 0 } } app.get('/', function(req, res){ .... });