Created
August 10, 2021 01:16
-
-
Save i-blis/b2f09e35bf7332ecf97e0e66b755ca9e to your computer and use it in GitHub Desktop.
Simple Password Generator
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
#!/usr/bin/env bb | |
(require '[clojure.tools.cli :refer [parse-opts]]) | |
(def generator (java.security.SecureRandom.)) | |
(defn gen-pass [alphabet length] | |
(let [bound (count alphabet) | |
idxs (repeatedly length #(.nextInt generator bound))] | |
(apply str (map alphabet idxs)))) | |
(def symbols {:uppercase "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
:lowercase "abcedfghijklmnopqrstuvwxyz" | |
:numerical "0123456789" | |
:special "!@#$%^&*"}) | |
(def default-length 16) | |
(let [parsed (-> *command-line-args* | |
(parse-opts [["-u" "--uppercase"] | |
["-l" "--lowercase"] | |
["-n" "--numerical"] | |
["-s" "--special"] | |
["-x" "--extras EXTRAS"]])) | |
options (parsed :options) | |
flags (or (keys options) (keys symbols)) | |
length (edn/read-string (first (:arguments parsed))) | |
length (if (integer? length) length default-length) | |
alphabet (->> flags (select-keys symbols) vals | |
(apply str (options :extras)) vec)] | |
(print (gen-pass alphabet length))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment