Created
March 2, 2010 18:06
-
-
Save drewr/319732 to your computer and use it in GitHub Desktop.
This file contains 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
;; Generate flickr/facebook-style secrets | |
(ns com.draines.genpass) | |
(def MIN 4) | |
(def MAX 4) | |
(defn limit-length [word a b] | |
(if (<= a b) | |
(let [l (count word)] | |
(and (>= l a) (<= l b))) | |
(throw (Exception. (format "%d not less than %d" a b))))) | |
(defn limited [words min max] | |
(filter #(limit-length % min max) words)) | |
(defn lowered [words] | |
(map #(.toLowerCase %) words)) | |
(def make-db (memoize | |
(fn [file min max] | |
(-> file | |
java.io.FileReader. | |
java.io.BufferedReader. | |
line-seq | |
(limited min max) | |
lowered)))) | |
(defn genpass [min max] | |
(let [words (make-db "/usr/share/dict/words" min max) | |
word1 (nth words (rand-int (count words))) | |
word2 (nth words (rand-int (count words))) | |
num (rand-int 100)] | |
(format "%s%02d%s" word1 num word2))) | |
(genpass MIN MAX) ;; "whap17tech" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment