-
Notifications
You must be signed in to change notification settings - Fork 3
/
shellPass.sh
executable file
·82 lines (74 loc) · 3.33 KB
/
shellPass.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
export LANG=C
#----------------------------------------------------|
# Matheus Martins [email protected]
# https://github.com/mateuscomh/yoURL
# 30/03/2021 3.2.0 GPL3
# Generate secure passwords on terminal
# Depends: xclip on GNU/Linux / pbcopy on IOS
#----------------------------------------------------|
FECHA="\033[m"
BOLD=$(tput bold)
ITALIC=$(tput dim)
main() {
local VERSION="Ver:3.2.1"
local AUTHOR="Matheus [email protected]"
local USAGE="Program to generate random passwords on CLI
███████╗██╗ ██╗███████╗██╗ ██╗ ██████╗ █████╗ ▄▄███▄▄·▄▄███▄▄·
██╔════╝██║ ██║██╔════╝██║ ██║ ██╔══██╗██╔══██╗██╔════╝██╔════╝
███████╗███████║█████╗ ██║ ██║ ██████╔╝███████║███████╗███████╗
╚════██║██╔══██║██╔══╝ ██║ ██║ ██╔═══╝ ██╔══██║╚════██║╚════██║
███████║██║ ██║███████╗███████╗███████╗██║ ██║ ██║███████║███████║
╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝ ╚═╝╚═▀▀▀══╝╚═▀▀▀══╝ "
local MAX="$1"
local TIPO="$2"
echo -e "$USAGE"
case "$MAX" in
v | -v | --version ) echo -e "${BOLD} $VERSION / $AUTHOR ${FECHA}"; return;;
* ) echo "$VERSION"; _checkSize; _checkType ;;
esac
case "$TIPO" in
1)
CPX='0-9' ;;
2)
CPX='a-z0-9A-Z' ;;
3)
CPX='A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_{|}~' ;;
q|Q) echo "Bye..."; exit ;;
esac
_makePass
_writeinfile
}
_checkSize() {
while [[ -z "$MAX" || "$MAX" == *[^[:digit:]]* || "$MAX" -lt 1 ]]; do
echo -e "${BOLD} Enter the QUANTITY of characters for the password or [Q]uit: ${FECHA}"
read -r MAX
[[ $MAX == [qQ] ]] && echo "Bye..." && exit 0
done
}
_checkType() {
while [[ "$TIPO" != [1-3] && "$TIPO" != [qQ] ]]; do
echo -e "${BOLD} Enter the TYPE [1,2,3] for password complexity you want or [Q]uit ${FECHA}
${ITALIC} 1 - Password only numbers ${FECHA}
${ITALIC} 2 - Password with LeTtErS and numb3rs ${FECHA}
${ITALIC} 3 - Password with LeTtErS, numb3rs and Sp3c1@l Ch@r@ct&rs ${FECHA}"
read -rsn 1 TIPO;
done
}
_writeinfile() {
SCRIPT_PATH="${BASH_SOURCE:-$0}"
ABS_SCRIPT_PATH="$(readlink -f "${SCRIPT_PATH}")"
ABS_DIRECTORY="$(dirname "${ABS_SCRIPT_PATH}")"
echo "$(date '+%d/%m/%y %H:%M:%S') - $PASS" >> "$ABS_DIRECTORY"/history.log
}
_makePass() {
PASS=$(cat /dev/urandom LC_ALL=C | tr -dc "$CPX"| head -c "$MAX")
case $(uname -s) in
Darwin) printf %s "$PASS" | pbcopy 2> /dev/null ;;
Linux) command -v xclip > /dev/null && { printf %s "$PASS" | xclip -sel copy; } ;;
*) echo "This is compatible only for GNU/Linux, MacOS or WSL2"; exit 1 ;;
esac
echo -e "${BOLD}$PASS${FECHA}"
}
#---Main
main "$1" "$2"