Files
Password-Generator/passwd-gen.sh

52 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
generate_password() {
local length="$1"
tr -dc A-Za-z0-9_\!\@\#\$\%\&\*\(\) < /dev/urandom | head -c "$length"
echo
}
passwords_file="password.txt"
echo "Адрес электронной почты?"
read email_choice
email_choice_lower=$(echo "$email_choice" | tr '[:upper:]' '[:lower:]')
if [[ "$email_choice_lower" == "yes" || "$email_choice_lower" == "y" ]]; then
read -p "Введите адрес электронной почты: " email
fi
echo "Cгенерировать пароль?:"
read generate_choice
generate_choice_lower=$(echo "$generate_choice" | tr '[:upper:]' '[:lower:]')
if [[ "$generate_choice_lower" == "yes" || "$generate_choice_lower" == "y" ]]; then
echo "Введите длину пароля:"
read password_length
generated_password=$(generate_password "$password_length")
else
read -s -p "Введите пароль: " user_password
echo
fi
echo "Введите название сервиса:"
read service_name
echo "Сервис: $service_name" >> "$passwords_file"
if [[ "$generate_choice_lower" == "yes" || "$generate_choice_lower" == "y" ]]; then
echo "Пароль: $generated_password" >> "$passwords_file"
else
echo "Пароль: $user_password" >> "$passwords_file"
fi
if [[ "$email_choice_lower" == "yes" || "$email_choice_lower" == "y" ]]; then
echo "Почта: $email" >> "$passwords_file"
fi
echo "" >> "$passwords_file"
echo "Информация сохранена в $passwords_file"