-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpwd_generator_guideline.sh
36 lines (28 loc) · 1.24 KB
/
pwd_generator_guideline.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
#!/bin/bash
## Generate a random password
PASSWORD="${RANDOM}"
echo "${PASSWORD}"
## Generate a random password based on seconds (which will increase every second)
PASSWORD=$(date +%s)
echo "${PASSWORD}"
## Generate a rather stronger random password based on nanoseconds
PASSWORD=$(date +%s%N)
echo "${PASSWORD}"
## Generate a 8-character password based on the sha256sum of nanoseconds
PASSWORD=$(date +%s%N | sha256sum | head -c8)
echo "${PASSWORD}"
## Generate a 8-character password based on the sha256sum of nanoseconds and random numbers in conjunction
PASSWORD=$(date +%s%N${RANDOM}${RANDOM} | sha256sum | head -c8)
echo "${PASSWORD}"
## Add special characters to the generated password
### Define special characters
S="!@#$%^&*()_-+="
### The 'shuf' method works on shuffling lines of text, you cannot shuffle a string directly, you must 'fold' it at first.
#### echo "${S}" | fold -b1 | shuf
### And retrieve the first line (including solely one character) from the shuffled, folded string
#### echo "${S}" | fold -b1 | shuf | head -n1
SPECIAL_CHAR=$(echo "${S}" | fold -b1 | shuf | head -n1)
PASSWORD=$(date +%s%N${RANDOM}${RANDOM} | sha256sum | head -c8)
echo "${PASSWORD}${SPECIAL_CHAR}"
# To notify user that this script is done successfully.
exit 0