Fix crash when enter characters on password generator

This commit is contained in:
q3aql 2022-06-29 20:00:41 +02:00
parent 3056dc35ad
commit d6ef9e7956
3 changed files with 130 additions and 82 deletions

View File

@ -109,25 +109,35 @@ function vault_key_decrypt() {
function generate_password() { function generate_password() {
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
default_long_password=20 default_long_password=20
elif [ ${1} -lt 8 ] ; then
default_long_password=10
else else
default_long_password=${1} expr ${1} + 1 &> /dev/null
fi num_error=$?
count_char_password=1 if [ ${num_error} -ne 0 ] ; then
current_password="" size_pass=20
echo "" else
echo "# Generating Random Password" size_pass="${1}"
while [ ${count_char_password} -le ${default_long_password} ] ; do fi
current_char=$(generate_codes "password") # Create password
current_password="${current_password}${current_char}" if [ ${size_pass} -lt 8 ] ; then
count_char_password=$(expr ${count_char_password} + 1) default_long_password=10
done else
echo "" default_long_password=${size_pass}
echo "# PASSWORD: ${current_password}" fi
echo "" count_char_password=1
if [ "${2}" != "param" ] ; then current_password=""
echo -n "# Press enter key to continue " ; read enter_continue echo ""
echo "# Generating Random Password"
while [ ${count_char_password} -le ${default_long_password} ] ; do
current_char=$(generate_codes "password")
current_password="${current_password}${current_char}"
count_char_password=$(expr ${count_char_password} + 1)
done
echo ""
echo "# PASSWORD: ${current_password}"
echo ""
if [ "${2}" != "param" ] ; then
echo -n "# Press enter key to continue " ; read enter_continue
fi
fi fi
} }

View File

@ -120,44 +120,64 @@ function vault_key_decrypt() {
function generate_password() { function generate_password() {
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
default_long_password=20 default_long_password=20
elif [ ${1} -lt 8 ] ; then
default_long_password=10
else else
default_long_password=${1} expr ${1} + 1 &> /dev/null
fi num_error=$?
count_char_password=1 if [ ${num_error} -ne 0 ] ; then
current_password="" size_pass=20
echo "" else
echo "# Generating Random Password" size_pass="${1}"
while [ ${count_char_password} -le ${default_long_password} ] ; do fi
current_char=$(generate_codes "password") # Create password
current_password="${current_password}${current_char}" if [ ${size_pass} -lt 8 ] ; then
count_char_password=$(expr ${count_char_password} + 1) default_long_password=10
done else
echo "" default_long_password=${size_pass}
echo "# PASSWORD: ${current_password}" fi
echo "" count_char_password=1
if [ "${2}" != "param" ] ; then current_password=""
echo -n "# Press enter key to continue " ; read enter_continue echo ""
echo "# Generating Random Password"
while [ ${count_char_password} -le ${default_long_password} ] ; do
current_char=$(generate_codes "password")
current_password="${current_password}${current_char}"
count_char_password=$(expr ${count_char_password} + 1)
done
echo ""
echo "# PASSWORD: ${current_password}"
echo ""
if [ "${2}" != "param" ] ; then
echo -n "# Press enter key to continue " ; read enter_continue
fi
fi fi
} }
function gen_password_dl() { function gen_password_dl() {
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
default_long_password=20 default_long_password=20
elif [ ${1} -lt 8 ] ; then
default_long_password=10
else else
default_long_password=${1} expr ${1} + 1 &> /dev/null
num_error=$?
if [ ${num_error} -ne 0 ] ; then
size_pass=20
else
size_pass="${1}"
fi
# Create password
if [ ${size_pass} -lt 8 ] ; then
default_long_password=10
else
default_long_password=${size_pass}
fi
count_char_password=1
current_password=""
while [ ${count_char_password} -le ${default_long_password} ] ; do
current_char=$(generate_codes "password")
current_password="${current_password}${current_char}"
count_char_password=$(expr ${count_char_password} + 1)
done
echo "${current_password}"
fi fi
count_char_password=1
current_password=""
while [ ${count_char_password} -le ${default_long_password} ] ; do
current_char=$(generate_codes "password")
current_password="${current_password}${current_char}"
count_char_password=$(expr ${count_char_password} + 1)
done
echo "${current_password}"
} }
function generate_password_menu() { function generate_password_menu() {

View File

@ -155,50 +155,68 @@ function vault_key_decrypt() {
function generate_password() { function generate_password() {
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
default_long_password=20 default_long_password=20
elif [ ${1} -lt 8 ] ; then
default_long_password=10
else else
default_long_password=${1} expr ${1} + 1 &> /dev/null
fi num_error=$?
count_char_password=1 if [ ${num_error} -ne 0 ] ; then
current_password="" size_pass=20
echo "" else
echo "# Generating Random Password" size_pass="${1}"
while [ ${count_char_password} -le ${default_long_password} ] ; do fi
current_char=$(generate_codes "password") # Create password
current_password="${current_password}${current_char}" if [ ${size_pass} -lt 8 ] ; then
count_char_password=$(expr ${count_char_password} + 1) default_long_password=10
done else
echo "" default_long_password=${size_pass}
echo "# PASSWORD: ${current_password}" fi
echo "" count_char_password=1
if [ "${2}" != "param" ] ; then current_password=""
echo -n "# Press enter key to continue " ; read enter_continue echo ""
echo "# Generating Random Password"
while [ ${count_char_password} -le ${default_long_password} ] ; do
current_char=$(generate_codes "password")
current_password="${current_password}${current_char}"
count_char_password=$(expr ${count_char_password} + 1)
done
echo ""
echo "# PASSWORD: ${current_password}"
echo ""
if [ "${2}" != "param" ] ; then
echo -n "# Press enter key to continue " ; read enter_continue
fi
fi fi
} }
function generate_password_gui() { function generate_password_gui() {
if [ -z "${1}" ] ; then if [ -z "${1}" ] ; then
default_long_password=20 default_long_password=20
elif [ ${1} -lt 8 ] ; then
default_long_password=10
elif [ ${1} -gt 30 ] ; then
default_long_password=30
else else
default_long_password=${1} expr ${1} + 1 &> /dev/null
num_error=$?
if [ ${num_error} -ne 0 ] ; then
size_pass=20
else
size_pass="${1}"
fi
# Create password
if [ ${size_pass} -lt 8 ] ; then
default_long_password=10
else
default_long_password=${size_pass}
fi
count_char_password=1
current_password=""
echo ""
echo "# Generating Random Password"
while [ ${count_char_password} -le ${default_long_password} ] ; do
current_char=$(generate_codes "password")
current_password="${current_password}${current_char}"
count_char_password=$(expr ${count_char_password} + 1)
done
echo ${current_password} >> ${pwsh_vault_password_copy}
echo > /dev/null | pwsh-vaultm -p " PASSWORD: ${current_password} $(generate_spaces 65)"
echo > /dev/null | pwsh-vaultm -p " Password has been copied to ${pwsh_vault_password_copy} $(generate_spaces 20)"
fi fi
count_char_password=1
current_password=""
echo ""
echo "# Generating Random Password"
while [ ${count_char_password} -le ${default_long_password} ] ; do
current_char=$(generate_codes "password")
current_password="${current_password}${current_char}"
count_char_password=$(expr ${count_char_password} + 1)
done
echo ${current_password} >> ${pwsh_vault_password_copy}
echo > /dev/null | pwsh-vaultm -p " PASSWORD: ${current_password} $(generate_spaces 65)"
echo > /dev/null | pwsh-vaultm -p " Password has been copied to ${pwsh_vault_password_copy} $(generate_spaces 20)"
} }
function generate_password_menu() { function generate_password_menu() {