Skip to content

Instantly share code, notes, and snippets.

@craftybones
Created June 4, 2021 10:48
Show Gist options
  • Save craftybones/3ac6a537933922744c8091f017e0faa2 to your computer and use it in GitHub Desktop.
Save craftybones/3ac6a537933922744c8091f017e0faa2 to your computer and use it in GitHub Desktop.
(defn length-between? [x y]
(fn [password] (<= x (count password) y)))
(def alpha-only? (partial re-matches #"^\p{Alpha}*$"))
(def digit-only? (partial re-matches #"^\p{Digit}*$"))
(def alpha-numeric? (partial re-matches #"^\p{Alnum}*$"))
(def special-char? (partial re-find #"[^\p{Alnum}]"))
(def classifiers {:weak [(length-between? 0 5)
(some-fn alpha-only? digit-only?)]
:medium [(length-between? 5 8)
alpha-numeric?]
:strong [(length-between? 8 ##Inf)
special-char?]})
(defn classifies? [password]
(fn [[classifier predicates]]
(let [pred (apply every-pred predicates)]
(when (pred password)
classifier))))
(defn classify [password]
(or (->> classifiers
(keep (classifies? password))
first)
:unknown))
(classify "abc")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment