Permalink
Browse files

Merge branch 'master' of git@github.com:brentonashworth/sandbar

  • Loading branch information...
brentonashworth committed Jun 20, 2011
2 parents 40e4fe2 + 223b4c3 commit 439322b40ae20e71f36c0cc4348d9e94ada923df
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/sandbar/auth.clj
View
@@ -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)

0 comments on commit 439322b

Please sign in to comment.