progs/app3.scala
changeset 93 82ac034dcc9d
child 98 3d585e603927
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/progs/app3.scala	Sun Sep 22 15:35:50 2013 +0100
@@ -0,0 +1,26 @@
+object Application extends Controller {
+
+  //SHA-1, SHA-256
+  def mk_hash(s: String) : String = {
+    val hash_fun = MessageDigest.getInstance("SHA-1")
+    hash_fun.digest(s.getBytes).map{ "%02x".format(_) }.mkString
+  }
+
+  def gt_cookie(c: Option[Cookie]) : Int = 
+    c.map(_.value.split("/")) match {
+      case Some(Array(s, h)) 
+        if (s.forall(_.isDigit) && mk_hash(s) == h) => s.toInt 
+      case _ => 0
+    }
+
+  def mk_cookie(i: Int) : Cookie = {
+    val s = i.toString
+    Cookie("visits", s + "/" + mk_hash(s))
+  }
+   
+  def index = Action { request => ... }     
+}
+
+
+
+