Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:brentonashworth/sandbar
Browse files Browse the repository at this point in the history
  • Loading branch information
brentonashworth committed Jun 20, 2011
2 parents 40e4fe2 + 223b4c3 commit 439322b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/sandbar/auth.clj
Expand Up @@ -121,14 +121,25 @@
:else false)
(partition 2 config))))

(defn gen-salt
"Generate a secure salt."
([] (gen-salt 8))
([n]
(let [random (java.security.SecureRandom.)
salt (make-array Byte/TYPE n)]
(.nextBytes random salt)
salt)))

(defn hash-password
"Generate a hash from the password and salt. Default value of n is
*hash-delay*."
([password salt] (hash-password password salt *hash-delay*))
([password salt n]
(let [digest (java.security.MessageDigest/getInstance "SHA-256")]
(do (.reset digest)
(.update digest (.getBytes salt "UTF-8")))
(.update digest (if (string? salt)
(.getBytes salt "UTF-8")
salt)))
(loop [input (.digest digest (.getBytes password "UTF-8"))
count n]
(if (= count 0)
Expand Down

0 comments on commit 439322b

Please sign in to comment.