-
Notifications
You must be signed in to change notification settings - Fork 0
/
makepass
executable file
·83 lines (65 loc) · 1.52 KB
/
makepass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Makepass: Generate passwords with the power of "tr"
# Version: 0.1
# Build: 2019-10-31
# Author: Heiko Barth
# Licence: Beer-Ware (See: http://en.wikipedia.org/wiki/Beerware)
APP=${0##*/}
VER=0.1
RNG=/dev/random
CHARSET=${1:-[:alnum:]} # default to 'all letters and digits'
COUNT=${2:-20} # default to 20
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
{
read -d '' CHARSETS <<-"EOF"
[:alnum:]
all letters and digits
[:alpha:]
all letters
[:blank:]
all horizontal whitespace
[:cntrl:]
all control characters
[:digit:]
all digits
[:graph:]
all printable characters, not including space
[:lower:]
all lower case letters
[:print:]
all printable characters, including space
[:punct:]
all punctuation characters
[:space:]
all horizontal or vertical whitespace
[:upper:]
all upper case letters
[:xdigit:]
all hexadecimal digits
EOF
echo "$APP $VER"
echo
echo "Syntax: $APP [<character set>] [<count>]"
echo
echo "Predefined character sets:"
echo
echo "$CHARSETS" | column -e
} >&2
exit 1
fi
checkBinarys() {
for i in "$@"; do
hash "$i" 2>/dev/null || {
echo "Binary missing: $i" >&2
echo >&2
exit 1
}
done
}
checkBinarys "head" "tr"
echo -n "Password: "
for ((i=1; i<=COUNT; i++)); do
echo -n "$(tr -dc "$CHARSET" < $RNG | head -c 1)"
done
echo
echo