equal
deleted
inserted
replaced
|
1 function mk_hash(s) { |
|
2 return crypto.createHash('sha1').update(s).digest('hex') |
|
3 } |
|
4 |
|
5 function mk_cookie(c) { |
|
6 return c.toString() + "-" + mk_hash(c.toString()) |
|
7 } |
|
8 |
|
9 function gt_cookie(s) { |
|
10 var splits = s.split("-", 2); |
|
11 var counter = parseInt(splits[0]) |
|
12 if (mk_hash(counter.toString()) == splits[1]) { |
|
13 return counter |
|
14 } else { return 0 } |
|
15 } |
|
16 |
|
17 app.get('/', function(req, res){ |
|
18 var counter = gt_cookie(req.cookies.counter) || 0; |
|
19 res.cookie('counter', mk_cookie(counter + 1)); |
|
20 ... |
|
21 }); |
|
22 |