0
0

[–] Frank_Castle [S] 0 points 0 points (+0|-0) ago 

Sweet... when-bind* is a nice macro:

(defun valid-cookie (str)
  "returns the userid for cookie if valid, otherwise nil"
  (when (= (count #\, str :test #'char=) 2)
    (when-bind* ((sn (subseq str 0 (position #\, str :test #'char=)))
                 (time (subseq str (+ 1 (length sn)) (position #\, str :from-end t :test #'char=)))
                 (hash (subseq str (+ (length sn) (length time) 2)))
                 (pass (user-pass sn)))
      (when (string= hash (hashstr (makestr time sn pass *secret*)))
        (user-id (get-user sn))))))

From cookiehash.lisp.