forked from inv4fee2020/pli_node_conf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_passwd.sh
120 lines (101 loc) · 3.34 KB
/
gen_passwd.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
PASS_KEYSTORE=""
PASS_POSTGRES=""
PASS_API=""
BEGIN=true
AGAIN=false
FUNC_GEN_KEYSTORE(){
digits='[[:digit:]].*[[:digit:]].*[[:digit:]]'
upper='[[:upper:]].*[[:upper:]].*[[:upper:]]'
lower='[[:lower:]].*[[:lower:]].*[[:lower:]]'
punct='[[:punct:]].*[[:punct:]].*[[:punct:]]'
while $BEGIN || (( len_pass < 8 && len_pass > 28 )) ||
[[ ! ( $test_pass =~ $digits && $test_pass =~ $upper && $test_pass =~ $lower && $test_pass =~ $punct ) ]]
do
#$AGAIN && echo "### Warning: Does not meet complexity - rehashing!" || AGAIN=true
$AGAIN || AGAIN=true
BEGIN=false
PASS_KEYSTORE=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9%:+*!;.?=' | head -c32)
if [[ ! -z $PASS_KEYSTORE ]]
then
len_pass=${#PASS_KEYSTORE}
test_pass=${PASS_KEYSTORE#?}
test_pass=${test_pass%?}
else
BEGIN=true
fi
done
#echo "new password is $PASS_KEYSTORE"
echo "$PASS_KEYSTORE"
#Credit: Grail @ https://www.linuxquestions.org/questions/programming-9/bash-password-complexity-script-898056/
}
FUNC_GEN_POSTGRES(){
digits='[[:digit:]].*[[:digit:]].*[[:digit:]]'
upper='[[:upper:]].*[[:upper:]].*[[:upper:]]'
lower='[[:lower:]].*[[:lower:]].*[[:lower:]]'
while $BEGIN || (( len_pass < 8 && len_pass > 28 )) ||
[[ ! ( $test_pass =~ $digits && $test_pass =~ $upper && $test_pass =~ $lower ) ]]
do
#$AGAIN && echo "### Warning: Does not meet complexity - rehashing!" || AGAIN=true
$AGAIN || AGAIN=true
BEGIN=false
PASS_POSTGRES=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1)
if [[ ! -z $PASS_POSTGRES ]]
then
len_pass=${#PASS_POSTGRES}
test_pass=${PASS_POSTGRES#?}
test_pass=${test_pass%?}
else
BEGIN=true
fi
done
#echo "new password is $PASS_POSTGRES"
echo "$PASS_POSTGRES"
}
FUNC_GEN_API(){
digits='[[:digit:]].*[[:digit:]].*[[:digit:]]'
upper='[[:upper:]].*[[:upper:]].*[[:upper:]]'
lower='[[:lower:]].*[[:lower:]].*[[:lower:]]'
while $BEGIN || (( len_pass < 8 && len_pass > 20 )) ||
[[ ! ( $test_pass =~ $digits && $test_pass =~ $upper && $test_pass =~ $lower ) ]]
do
#$AGAIN && echo "### Warning: Does not meet complexity - rehashing!" || AGAIN=true
$AGAIN || AGAIN=true
BEGIN=false
PASS_API=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w18 | head -n1)
if [[ ! -z $PASS_API ]]
then
len_pass=${#PASS_API}
test_pass=${PASS_API#?}
test_pass=${test_pass%?}
else
BEGIN=true
fi
done
#echo "new password is $PASS_API"
echo "$PASS_API"
}
case "$1" in
-keys)
FUNC_GEN_KEYSTORE
;;
-db)
FUNC_GEN_POSTGRES
;;
-api)
FUNC_GEN_API
;;
*)
echo
echo
echo "Usage: $0 {function}"
echo
echo "where {function} is one of the following;"
echo
echo " -keys == Randomly generates new keys secret that meets the requirements defined in readme & VARS file"
echo
echo " -db == Randomly generates new Postgres compatible password as defined in readme & VARS file"
echo
echo " -api == Randomly generates new node gui compatible password as defined in readme & VARS file"
echo
esac