blob: f4b28d695f1dd45a9e0c5f6e87a3c75af5ad0b64 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#!/bin/sh
# Simple random string generator for passwords and usernames
# $LEN initial declaration commented out for runtime LEN config
LC_ALL=C
#LEN=${LEN:-24}
ALPHA="A-Za-z"
NUM="0-9"
SPECIAL='!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~'
random() {
</dev/urandom tr -dc "${ALPHA}${NUM}${SPECIAL}" | dd bs=1 count=${LEN:-32} 2>/dev/null ; echo
}
case $1 in
pass)
random ;;
user)
LEN=${LEN:-12} SPECIAL='' random ;;
*)
printf "Usage: $0 pass|user\nSet LEN environment variable for length" ;;
esac
|