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: Option[Cookie]) : Int = |
|
10 c.map(_.value.split("/")) match { |
|
11 case Some(Array(s, h)) |
|
12 if (s.forall(_.isDigit) && mk_hash(s) == h) => s.toInt |
|
13 case _ => 0 |
|
14 } |
|
15 |
|
16 def mk_cookie(i: Int) : Cookie = { |
|
17 val s = i.toString |
|
18 Cookie("visits", s + "/" + mk_hash(s)) |
|
19 } |
|
20 |
|
21 def index = Action { request => ... } |
|
22 } |
|
23 |
|
24 |
|
25 |
|
26 |