equal
deleted
inserted
replaced
|
1 object Application extends Controller { |
|
2 |
|
3 //SHA-1, SHA-256 |
|
4 def mk_hash(s: String) : String = { |
|
5 val hash_fun = MessageDigest.getInstance("SHA-1") |
|
6 hash_fun.digest(s.getBytes).map{ "%02x".format(_) }.mkString |
|
7 } |
|
8 |
|
9 def gt_cookie(c: Cookie) : Int = c.value.split("/") match { |
|
10 case Array(s, h) |
|
11 if (s.forall(_.isDigit) && mk_hash(s) == h) => s.toInt |
|
12 case _ => 0 |
|
13 } |
|
14 |
|
15 def mk_cookie(i: Int) : Cookie = { |
|
16 val hash = mk_hash(i.toString) |
|
17 Cookie("visits", s"$i/$hash") |
|
18 } |
|
19 |
|
20 def index = Action { request => ... } |
|
21 } |
|
22 |
|
23 |
|
24 |
|
25 |