Skip to content

Commit 7dab965

Browse files
authored
Merge pull request #9 from mateuscomh/release2
Release2.7
2 parents 53c37e1 + f851e4d commit 7dab965

1 file changed

Lines changed: 57 additions & 36 deletions

File tree

shellPass.sh

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,94 @@
33
#------------------------------------------------------------------------------|
44
# AUTOR : Matheus Martins <3mhenrique@gmail.com>
55
# HOMEPAGE : https://github.com/mateuscomh/shellPass
6-
# DATE/VER. : 29/08/2020 2.4
6+
# DATE/VER. : 29/08/2020 2.7
77
# LICENCE : GPL3
88
# SHORT DESC : Shell Script to generate fast passwords on terminal
9-
# DEPS : xclip on GNU/Linux / pbcopy on MacOS
9+
# DEPS : xclip in GNU/Linux / pbcopy in MacOS
1010

1111
#------------------------------------------------------------------------------|
1212
export LANG=C
13-
VERSION='2.4 by Matheus Martins'
14-
USAGE="Program to generate on shell passwords whith alpanum on terminal
13+
VERSION='2.7 by Matheus Martins'
14+
USAGE="Program to generate on shell random passwords
1515
░▒█▀▀▀█░█░░░░█▀▀░█░░█░░▄▀▀▄░█▀▀▄░█▀▀░█▀▀
1616
░░▀▀▀▄▄░█▀▀█░█▀▀░█░░█░░█▄▄█░█▄▄█░▀▀▄░▀▀▄
1717
░▒█▄▄▄█░▀░░▀░▀▀▀░▀▀░▀▀░█░░░░▀░░▀░▀▀▀░▀▀▀ "
1818
FECHA='\033[m'
19-
VERDE='\033[32;1m'
20-
VERMELHO='\033[31;1m'
21-
AMARELO='\033[01;33m'
19+
BOLD=$(tput bold)
20+
BLINK=$(tput blink)
21+
ITALIC=$(tput dim)
2222
MAX=$1
2323
#----------FUNC-------------------------------------------------------------|
24-
25-
_gerarsenha(){
26-
if [ -z "$MAX" ] || [ "$MAX" -eq 0 ]; then
24+
clear
25+
_getsize(){
26+
while [[ -z "$MAX" || $MAX == *[^[:digit:]]* || $MAX == 0 ]]; do
2727
clear
2828
echo -e "$USAGE \n"
29-
echo -e "${VERDE} Enter the QUANTITY of characters for the password or [Q] to quit: ${FECHA}"
29+
echo -e "${BOLD} Enter the QUANTITY of characters for the password or [Q] to quit: ${FECHA}"
3030
read -r MAX
31-
fi
32-
31+
[[ $MAX == [qQ] ]] && exit 0
32+
done
33+
return 0
34+
}
35+
_makepass(){
3336
case $MAX in
3437
q|Q)
3538
echo -e "Quiting..."
3639
exit 0
3740
;;
3841
''|*[!0-9]*)
39-
echo -e "${VERMELHO} Enter only numbers referring to the SIZE of the password ${FECHA}"
40-
return 1
42+
echo -e "${BLINK} Invalid option. ${FECHA}"
43+
_getsize
4144
;;
4245
[0-9]*)
43-
echo -e "${VERDE} Enter the TYPE of password complexity you want: ${FECHA}
44-
${AMARELO} 1 - Password only numbers ${FECHA}
45-
${AMARELO} 2 - Password with LeTtErS and numb3rs ${FECHA}
46-
${AMARELO} 3 - Password with LeTtErS, numb3rs and Speci@l Ch@r@ct&rs ${FECHA}";
47-
read -sn 1 TIPO;
46+
echo -e "${BOLD} Enter the TYPE of password complexity you want: ${FECHA}
47+
${ITALIC} 1 - Password only numbers ${FECHA}
48+
${ITALIC} 2 - Password with LeTtErS and numb3rs ${FECHA}
49+
${ITALIC} 3 - Password with LeTtErS, numb3rs and Speci@l Ch@r@ct&rs ${FECHA}";
50+
read -rsn 1 TIPO;
4851

4952
case "$TIPO" in
53+
q|Q)
54+
echo -e "Bye.." && exit 0
55+
;;
5056
''|*[!0-9]*)
51-
echo -e "${VERMELHO} Enter only numbers referring to the TYPE of the password ${FECHA}"
57+
echo -e "${BLINK} Enter only numbers referring to the TYPE of the password ${FECHA}"
5258
return 2
5359
;;
5460
1)
5561
PASS=$(cat /dev/urandom LC_ALL=C | tr -dc '0-9' | head -c "$MAX")
5662
command -v xclip > /dev/null && echo -n "$PASS" | xclip -sel copy || echo -n "$PASS" | pbcopy 2> /dev/null
57-
echo -e "${VERDE}$PASS${FECHA}"
63+
echo -e "${BOLD}$PASS${FECHA}"
5864
;;
5965
2)
6066
PASS=$(cat /dev/urandom LC_ALL=C | tr -dc 'A-Za-z0-9' | head -c "$MAX")
6167
command -v xclip > /dev/null && echo -n "$PASS" | xclip -sel copy || echo -n "$PASS" | pbcopy 2> /dev/null
62-
echo -e "${VERDE}$PASS${FECHA}"
68+
echo -e "${BOLD}$PASS${FECHA}"
6369
;;
6470
3)
6571
PASS=$(cat /dev/urandom LC_ALL=C |
6672
tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_{|}~' | head -c "$MAX")
6773
command -v xclip > /dev/null && echo -n "$PASS" | xclip -sel copy || echo -n "$PASS" | pbcopy 2> /dev/null
68-
echo -e "${VERDE}$PASS${FECHA}"
74+
echo -e "${BOLD}$PASS${FECHA}"
6975
;;
7076
*)
71-
echo -e "${VERMELHO} Use only the options [1,2,3] ${FECHA}"
77+
echo -e "${BLINK} Use only the options [1,2,3] ${FECHA}"
7278
return 1
7379
;;
7480
esac
7581
esac
76-
# write in file
77-
echo "$(date '+%d/%m/%y %H:%M:%S') - $PASS" >> $(pwd)/history.log
82+
_writeinfile
83+
}
84+
85+
_writeinfile(){
86+
SCRIPT_PATH="${BASH_SOURCE:-$0}"
87+
ABS_SCRIPT_PATH="$(realpath "${SCRIPT_PATH}")"
88+
ABS_DIRECTORY="$(dirname "${ABS_SCRIPT_PATH}")"
89+
echo "$(date '+%d/%m/%y %H:%M:%S') - $PASS" >> $ABS_DIRECTORY/history.log
90+
}
7891

92+
_askprint(){
93+
read -rn 1 -p "[R]epeat, generate new password [Y/N] or [Q]uit program? [Y/N/R/Q]" OP; echo
7994
}
8095
#---------MAIN-------------------------------------------------------------------|
8196

@@ -85,28 +100,34 @@ case "$MAX" in
85100
exit 0
86101
;;
87102
v | -v | --version )
88-
echo -e "${VERDE} $VERSION ${FECHA}"
103+
echo -e "${BOLD} $VERSION ${FECHA}"
89104
exit 0
90105
;;
91106
'')
92107
OP='Y'
93108
while true; do
94109
if [[ "$OP" = [yYsS] ]]; then
95110
MAX=0
96-
_gerarsenha
97-
read -n 1 -p "Do you want to [R]epeat or generate new password? [Y/N/R]" OP; echo
111+
_getsize
112+
_makepass
113+
_askprint
98114
elif [[ "$OP" = [rR] ]]; then
99-
_gerarsenha
100-
read -n 1 -p "Do you want to [R]epeat or generate new password? [Y/N/R]" OP; echo
101-
elif [[ "$OP" = [nN] ]]; then
115+
_getsize
116+
_makepass
117+
_askprint
118+
elif [[ "$OP" = [nNqQ] ]]; then
119+
echo -e "bye.."
102120
break
103121
else
104-
echo -e "${VERMELHO} Invalid option ${FECHA}"
105-
read -n 1 -p "Do you want to [R]epeat or generate new password? [Y/N/R]" OP; echo
122+
echo -e "${BLINK} Invalid option ${FECHA}"
123+
_askprint
106124
fi
107125
done
108126
;;
109127
[0-9]*)
110-
_gerarsenha
128+
_makepass
129+
;;
130+
*[!0-9]*)
131+
echo -e "${BOLD} Invalid option, call again. ${FECHA}" && exit 1
111132
;;
112133
esac

0 commit comments

Comments
 (0)