aboutsummaryrefslogtreecommitdiff
path: root/src/genpass/gen.cljc
blob: 12dbc2fe8e2be9b2c16edb4f269774bf06c592f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(ns genpass.gen)

(def low-case [\a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \W \x \Y \z])
(def upper-case [\A \B \C \D \E \F \G \H \I \J \K \L \M \N \O \P \Q \R \S \T \U \V \W \X \Y \Z])
(def number [\0 \1 \2 \3 \4 \5 \6 \7 \8 \9])
(def special-char [\! \@ \# \% \^ \& \* \( \) \{ \} \[ \] \- \+ \= \~])
(def all-char (concat low-case upper-case number special-char))

(defn rand-char []
  (nth all-char (rand-int (dec (count all-char)))))

(defn genpwd
  ([] (genpwd 12))
  ([length]
   (->> (range length)
        (map (fn [_] (rand-char)))
        (apply str))))