Created
June 4, 2021 10:48
-
-
Save craftybones/3ac6a537933922744c8091f017e0faa2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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