I am trying to make a bash script that will generate a password. The script also has a "Forgot password" option. Because the password has random characters, it's hard to remember, so when a user forgets the pass it can be regenerated but, of course, there have to be security questions.
I figured out the part where I can ask a user 3 questions and generate a password. For example: username, favorite food and url. The part I can't seem to figure out is where a user can regenerate the password. I think I need to somehow store 3 variables (username, favoriteFood, url) but I have no idea how. This is the code that I have:
#!/bin/bash
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
one(){
echo "Enter your usename"
read username
echo "Whats your favorite food"
read favoriteFood
echo "Enter URL"
read url
choose() { echo ${1:RANDOM%${#1}:1} $RANDOM; }
pass="$({ choose '!@#$%^\&'
choose '0123456789'
choose 'abcdefghijklmnopqrstuvwxyz'
choose 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in $( seq 1 $(( 4 + RANDOM % 8 )) )
do
choose '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
done
} | sort -R | awk '{printf "%s",$1}')"
echo "Your pass is:"$pass
pause
}
#this is the part where i am stuck
two(){
echo "Enter username"
read username2
echo "Whats your favorite food"
read favoriteFood2
echo "Enter URL"
read url2
if [ username==username2 -a favoriteFood==favoriteFood2 -a url==url2 ] #this only works if the scirpt is not closed.
then
echo $pass
else
echo "not found"
fi
pause
}
show_menus() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~"
echo " M A I N - M E N U"
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "1. Generate password"
echo "2. Forgot password"
echo "3. Exit"
}
read_options(){
local choice
read -p "Enter choice [ 1 - 3] " choice
case $choice in
1) one ;;
2) two ;;
3) exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 2
esac
}
trap '' SIGINT SIGQUIT SIGTSTP
while true
do
show_menus
read_options
done