Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
factor out separate bcrypt-verify fn
Browse files Browse the repository at this point in the history
  • Loading branch information
cemerick committed Dec 14, 2012
1 parent 7620c72 commit e23d36e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cemerick/friend/credentials.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
(BCrypt/gensalt work-factor) (BCrypt/gensalt work-factor)
(BCrypt/gensalt)))) (BCrypt/gensalt))))


(defn bcrypt-verify
"Returns true if the plaintext [password] corresponds to [hash],
the result of previously hashing that password."
[password hash]
(BCrypt/checkpw password hash))

(defn bcrypt-credential-fn (defn bcrypt-credential-fn
"A bcrypt credentials function intended to be used with `cemerick.friend/authenticate` "A bcrypt credentials function intended to be used with `cemerick.friend/authenticate`
or individual authentication workflows. You must supply a function of one argument or individual authentication workflows. You must supply a function of one argument
Expand Down Expand Up @@ -38,5 +44,5 @@
[load-credentials-fn {:keys [username password]}] [load-credentials-fn {:keys [username password]}]
(when-let [creds (load-credentials-fn username)] (when-let [creds (load-credentials-fn username)]
(let [password-key (or (-> creds meta ::password-key) :password)] (let [password-key (or (-> creds meta ::password-key) :password)]
(when (BCrypt/checkpw password (get creds password-key)) (when (bcrypt-verify password (get creds password-key))
(dissoc creds password-key))))) (dissoc creds password-key)))))

0 comments on commit e23d36e

Please sign in to comment.