forked from this8/password-generators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.sh
executable file
·61 lines (47 loc) · 1.27 KB
/
password_generator.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
#!/bin/bash
readonly lower_case="bcdfghjklmnpqrstvwxyz"
readonly upper_case="BCDFGHJKLMNPQRSTVWXYZ"
readonly vowels="aAeEiIoOuU"
readonly numbers="0123456789"
readonly symbols="\`-=[]\;,./~!@#$%^&*()_+{}|:<>?"
readonly characters="${lower_case}${upper_case}${vowels}${numbers}${symbols}"
function len() {
echo -n "$1" | wc -c
}
function randInt() {
local min=$1
local max=$2
echo $RANDOM % "$max" + "$min"
}
function randomFromString() {
local selectionString=$1
local random
random=$(randInt 0 "$(len "$selectionString")")
echo "${selectionString:$random:1}"
}
function randomCharacter() {
randomFromString "$characters"
}
function randomDigit() {
randomFromString "$numbers"
}
function randomPassword() {
local length_for_password=$1
local password=""
for (( i=1; i<=length_for_password; i++ ))
do
password+=$(randomCharacter)
done
echo "$password"
}
function readablePassword() {
local password=""
local letters="${lower_case}${upper_case}"
for i in {1..3}
do
password+=$(randomFromString $letters)
password+=$(randomFromString $letters)
password+=$(randomFromString "$( (("$i"%2)) && echo "$symbols" || echo "$numbers" )")
done
echo "$password"
}