-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass
executable file
·56 lines (48 loc) · 1.14 KB
/
pass
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
#!/bin/bash
#region Constantes
UPPER="A-Z"
LOWER="a-z"
NUMBERS="0-9"
SYMBOLS="!@#$%&*()?{}[]:;|_='\-"
CLR_ROJO="\e[91m"
CLR_FIN="\e[m"
#endregion
_error() {
echo -e "${CLR_ROJO}$(basename "$0"): $1${CLR_FIN}" >&2
}
main() {
local caracteres=$(procesar_argumentos $@)
if [ -z "$caracteres" ]; then
return 1
fi
generar_contraseñas "$caracteres"
}
procesar_argumentos() {
if [ "$1" ]; then
local an=
while [ "$1" ]; do
case "$1" in
-an) echo -n "$NUMBERS$UPPER$LOWER" ;;
-may) echo -n "$UPPER" ;;
-min) echo -n "$LOWER" ;;
-num) echo -n "$NUMBERS" ;;
-sym) echo -n "$SYMBOLS" ;;
*) _error "argumento $1 desconocido"
esac
shift
done
else
echo "$UPPER$LOWER$NUMBERS$SYMBOLS"
fi
}
generar_contraseñas() {
local caracteres="$1"
local cantidad=$(($RANDOM % 5 + 5))
local tamano
for (( i=0; i<$cantidad; i++ )); do
tamano=$(($RANDOM % 8 + 8))
head /dev/urandom | tr -dc $caracteres | head -c $tamano
echo
done
}
main "$@"