Skip to content

Instantly share code, notes, and snippets.

@hlship
Last active August 29, 2015 14:05
Show Gist options
  • Save hlship/fb0496b49088a6845e96 to your computer and use it in GitHub Desktop.
Save hlship/fb0496b49088a6845e96 to your computer and use it in GitHub Desktop.
(defn validate-auth
"Validates the authentication data and returns vector of [error-message user-data]. On success, the error-message will
be nil."
[db-connection user-id user-password]
(cond
(str/is-blank? user-id)
["user-id not specified"]
(str/is-blank? user-password)
["password not specified"]
:else
(let [user-data (read-user-by-id db-connection user-id)]
(cond
(nil? user-data)
["user not found"]
(not (password/is-valid? (:password-hash user-data)) user-password)
["password not valid"]
(:is-expired user-data)
["user has expired"]
:else
[nil (dissoc user-data :password-hash)]))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment