/
random_password.sh
executable file
·80 lines (67 loc) · 1.21 KB
/
random_password.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
#!/bin/bash
dot ()
{
while [ 1 ]
do
echo -ne "."
sleep 0.2
done
}
generate_password ()
{
< /dev/urandom LC_CTYPE=C tr -dc _A-Z-a-z-0-9 | head -c$length
}
in_process ()
{
rand_num=$((2 + $RANDOM % 10))
password=$(generate_password)
echo -n "Password being generated"
dot &
pid=$!
for i in `seq 1 $rand_num`
do
sleep 1
done
kill $pid
wait $pid 2> /dev/null
echo
echo "Your password: ${password}"
sleep 0.8
}
password_length ()
{
echo
sleep 0.5
x=0
while [ $x = 0 ]
do
read -p 'Enter the number length > ' length
if [[ "$length" =~ ^[0-9]+$ ]]; then
x=1
else
echo "Please enter the number"
fi
done
}
cat << END
Welcome to a Password Shop!
We generate a random alphanumeric password for you.
You can set up the length of a number for the password.
END
password_length
in_process
while [ 1 ]
do
read -p 'Do you want new different one? (y/n): ' answer
if [ "$answer" = 'y' ]; then
password_length
in_process
elif [ "$answer" = 'n' ]; then
echo
figlet -f rozzo "Have a Good One!"
exit
else
"$answer" 2> /dev/null
echo "That is not an option"
fi
done