forked from Capetian/SoalShift_modul1_A02
-
Notifications
You must be signed in to change notification settings - Fork 0
/
soal3.sh
57 lines (45 loc) · 792 Bytes
/
soal3.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
#!/bin/bash
gen_pass() {
loop=1
pass=""
while [[ $loop == 1 ]];
do
seed=$(date +%s%N)
pass=$(echo $seed | sha256sum | base64 | head -c 12)
if [[ $pass =~ ^.*[0-9]+.*$ && $pass =~ ^.*[A-Z]+.*$ && $pass =~ ^.*[a-z]+.*$ ]];
then loop=0
fi
done
echo $pass
}
check_pass() {
pass=$1
for i in $PWD/password*.txt
do cat $i >> temp.txt
done
loop=1
check=0
while [[ $loop == 1 ]];
do
check=$(awk -v curr="$pass" '$1 ~ curr {print 1}' temp.txt)
if [[ $check != 1 ]];
then loop=0
rm temp.txt
else pass=$(gen_pass)
fi
done
echo $pass
}
pass=$(gen_pass)
name="password"
index=1
if [[ -e $name$index.txt ]];
then
pass=$(check_pass $pass)
while [[ -e $name$index.txt ]];
do
let index++
done
fi
name=$name$index
echo $pass > $name.txt