On Mon, Jun 13, 2011 at 5:47 PM, Mark Rathwell <[email protected]> wrote:
>
> This, or wrap user-pass with seq in the conditional, which will return nil
> for an empty list:
> (defn authenticate?
>  [uri name pass]
>  (loop [user-pass (seq (partition 2 (.getStringArray *conf*
> "authentication")))]
>    (if (seq user-pass)
>      (if (re-matches (re-pattern (ffirst user-pass)) uri)
>        true
>        (recur (rest user-pass)))
>      false)))

Or use HOFs instead of loop/recur:

(defn authenticate? [uri name pass]
  (some
    #(re-matches (re-pattern (first %)) uri)
    (partition 2 (.getStringArray *conf* "authentication"))))

Of course, once you flesh this out to check the password as well, you
need both parts and destructuring becomes preferable:

(defn authenticate? [uri name pass]
  (some
    (fn [[conf-uri conf-pass]]
      (and
        (re-matches (re-pattern conf-uri) uri)
        (= conf-pass (apply-some-sort-of-hash pass))))
    (partition 2 (.getStringArray *conf* "authentication"))))

You'd probably also want to hoist the password hashing out of the loop
and the reading of the conf file, unless you expect to have to
accommodate changes on the fly, out of the function entirely into a
def. Not sure what you had in mind with the "name" parameter though,
or why you're using regexp stuff to compare usernames. :)

-- 
Protege: What is this seething mass of parentheses?!
Master: Your father's Lisp REPL. This is the language of a true
hacker. Not as clumsy or random as C++; a language for a more
civilized age.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to