-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.sh
executable file
·57 lines (47 loc) · 1.56 KB
/
run.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
#!/bin/bash
#############
# File name: run.sh
# Purpose: When executed, this will copy a complex password to the user's clipboard
# Created by: Christophe El-Khoury (thelebdev)
# Created at: 24-02-2021, Byblos - Lebanon
###########
# Array holding all of the characters used in the password
DICTIONARY=(a b c d e f g h i j k l m n o p q r s t u v w x y n z A B C D E F G H I J K L M N O P Q R S T U V W X Y N Z ! \" \# \$ \% \& \' \( \) \* \+ \, \- \. \/ \: \; \< \= \> \? \@ \[ \\ \] \^ \_ \` \{ \| \} \~ )
# User's input, the password's length
PASSWORD_LENGTH=$1
###
# This function will validate a user's confirmation choice
###
function VALIDATE_CONFIRMATION {
read CONFIRMATION
echo $CONFIRMATION
if [[ $CONFIRMATION != "y" ]] && [[ $CONFIRMATION != "Y" ]]
then
echo "Aborting..."
exit 1
fi
}
if [ -z $PASSWORD_LENGTH ]
then
PASSWORD_LENGTH=14
echo "Generating password of length ${PASSWORD_LENGTH} (default)"
else
echo "Generating password of length ${PASSWORD_LENGTH} (custom)"
fi
if [ $PASSWORD_LENGTH -lt 6 ]
then
echo "You are generating a weak password ($PASSWORD_LENGTH characters). Are you sure you want to continue? (y/n)"
VALIDATE_CONFIRMATION
fi
if [ $PASSWORD_LENGTH -gt 30 ]
then
echo "You are generating a very long password ($PASSWORD_LENGTH characters). Are you sure you want to continue? (y/n)"
VALIDATE_CONFIRMATION
fi
PASSWORD=""
for (( c=0; c<$PASSWORD_LENGTH; c++ ))
do
PASSWORD=$PASSWORD${DICTIONARY[$RANDOM % ${#DICTIONARY[@]}]}
done
echo "Password copied in your clipboard"
echo $PASSWORD | pbcopy