anchor.diff:                                      (mkdoc "map"
                                              (couchfun (doc &aux (type (hashget doc "type")))
                                                (when (equal type "account")
  -                                               (emit (hashget doc "username")
  +                                               (emit (string-downcase (hashget doc "username"))
                                                        doc))))
                                       "password_validation"
                                       (mkdoc "map"
                                              (couchfun (doc &aux (type (hashget doc "type")))
                                                (when (equal type "account")
  -                                               (emit (list (hashget doc "username")
  +                                               (emit (list (string-downcase (hashget doc "username"))
                                                              (hashget doc "password"))
                                                        doc))))))
                 (mkdoc "language" "javascript"
  
positive.code:                      "password" (hash-password password))))
  
  (defun find-account (username)
    (when-let((results (doc-val (query-view *db* "account" "by_username"
                                            :key username)
                                "rows")))
      (doc-val (car results)
               "value")))
  
  (defun validate-credentials (username password)
    (when-let ((results (doc-val (query-view *db* "account" "by_username_password"
                                             :key (list username (hash-password password)))
                                 "rows")))
      (doc-val (car results)
               "value")))
  
negative.code:                                     (mkdoc "map"
                                       "function (doc) {
                                         if (doc.type == 'account') {
                                           emit(doc.username.toLowerCase(),doc);
                                         }
                                       }")
                                      "by_username_password"
                                      (mkdoc "map"
                                       "function (doc) {
                                         if (doc.type == 'account') {
                                           emit([doc.username.toLowerCase(),doc.password],doc);
                                         }
                                       }")))))
  
  