Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
- The problem statement, all variables and given/known data:
Hi guys. My case study is about creating a script that includes password recovery whenever a user forgets his/her password. I was not allowed by my instructor to have the login script of the admin.
So, I created a script in my account that will show only a sample. I have a "useradd" script in which a user can create an account in my account. He/she will enter his/her username, password, answer to 5 questions for password recovery. His/her information will be stored in the "login_users" script. And then, in the "profile" script, he can now have a chance to login.
My main problem is, if he/she entered a wrong password, it goes back to the profile script again without saying the, "did you forgot your password?" and he can't have a chance to choose which to answer in the 5 questions. I think there's a problem in my "login" script and I ask for your assistance.
Also, my problem in the "login" script is, how can I recover an info from a script to another script?? like for example, "pass" is a variable assigned for the real password of the user when he created an account in the "useradd" script, the info is stored in the "login_users" script. how can I access pass in the "login" script I have??
Another is, how can I hide the login_users script, because it should be hidden because all the info of the users are in there including there passwords.
Lastly, how can I hide the password whenever a user logs in. Usually, password is invisible in the login..
You can try my scripts to understand my problems, Thank you.
- Relevant commands, code, scripts, algorithms:
Here are the related scripts: profile, useradd, userlist, (the login_users script will have a content whenever there's an account added in the useradd script)
#============================================================
# Script Name: profile
# By: JRG
# Date: March 5, 2011
# Purpose: main menu
# Command Line: profile
#===========================================================
profile=~/casestudies/users
loop=y
while [ "$loop" = y ]
do
clear
tput cup 3 12; echo " Welcome to your profile "
tput cup 4 12; echo "==========================="
tput cup 6 9; echo "What do you want to do? "
tput cup 7 9; echo "C - create an account"
tput cup 8 9; echo "L - Login"
tput cup 9 9; echo "Q - Quit"
read choice || continue
case $choice in
[Cc]) ./useradd;;
[Ll]) ./login1 ;;
[Qq]) exit ;;
*) tput cup 13 4; echo "Invalid Code"; read choice ;;
esac
done
#============================================================
# Script Name: userlist
# By: JRG
# Date: March 5, 2011
# Purpose: Use awk to format colon-separated fields
# in a flat file and display to the screen
# Command Line: userlist
#===========================================================
clear
tput cup 2 20; echo "User List"
tput cup 3 20; echo "========="
tput cup 5 0; echo "P - Print User List"
awk -F: '{printf "%-12s %-12s %s\t%s %s %10.10s %s\n", $2, $3, $4, $1, $5, $6, $7}' login_users
#============================================================
# Script Name: useradd
# By: JRG
# Date: March 5, 2011
# Purpose: A shell script used to add
# new user accounts to the login_users file
# Command Line: useradd
#===========================================================
trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3
userfile=~/casestudies/login_users
clear
tput cup 1 4; echo "User Accounts Additions"
tput cup 2 4; echo "======================="
tput cup 4 4; echo "Username : "
tput cup 5 4; echo "Password : "
tput cup 6 4; echo "Answer the following questions in case of password recovery"
tput cup 7 4; echo "A. What is your 5th favorite color? "
tput cup 8 4; echo "B. What is your favorite food? "
tput cup 9 4; echo "C. What is the name of your pet? "
tput cup 10 4; echo "D. What is the middle name of your mother's maiden name? "
tput cup 11 4; echo "E. What is the model number of your laptop/monitor? "
tput cup 13 4; echo "(Q)uit: "
if [ "$username" = "q" ]
then
clear; exit
fi
tput cup 4 18; read username
tput cup 5 18; read passwd
tput cup 7 18; read A
tput cup 8 18; read B
tput cup 9 18; read C
tput cup 10 18; read D
tput cup 11 18; read E
# Check to see if username is not blank before you
#write to disk
if [ "$username" > " " ]
then echo "$username:$passwd:$A:$B:$C:$D:$E" >> $userfile
fi
tput cup 13 10; echo -n "(q)uit: "
tput cup 13 10; read choice
if [ "$choice" = "q" ]
then
clear; exit
fi
- The attempts at a solution (include all code and scripts):
This is the script in which I'm having a problem, this is my attempted script,
#============================================================
# Script Name: login1
# By: JRG
# Date: March 5, 2011
# Purpose: A shell script that enables a user to
# login and recover password
# Command Line: login
#===========================================================
trap "rm ~/tmp/* 2> /dev/null; exit" 0 1 2 3
userfile=~/casestudies/login_users
clear
echo " Login "
echo "================="
echo -n "Username: " ; read username
echo -n "Password: " ; read passwd
while ["$pass" != "$passwd"]; do
echo "Incorrect password."
echo -n "Did you forgot your password (y)es or (n)o?: "
read choice || continue
case $choice in
[Nn]) echo "Verify Password: " ; read passwd;
done
while ["$answer"!="$A|$B|$C|$D"]do
[Yy]) echo "Then choose a question to answer below"
echo "A. What is your 5th favorite color? "
echo "B. What is your favorite food? "
echo "C. What is the name of your pet? "
echo "D. What is the middle name of your mother's maiden name? "
echo "E. What is the model number of your laptop/monitor? "
read question || continue
case $question in
[Aa]) echo -n "answer: " ; read answer
if["$answer"="$A"]
then
echo "Correct, your password is: " $pass
else
echo "Incorrect. Choose another question to answer." ; read answer
fi ;;
[Bb])echo -n "answer: " ; read answer
if["$answer"="$B"]
then
echo "Correct, your password is: " $pass
else
echo "Incorrect. Choose another question to answer." ; read answer
fi ;;
[Cc])echo -n "answer: " ; read answer
if["$answer"="$C"]
then
echo "Correct, your password is: " $pass
else
echo "Incorrect. Choose another question to answer." ; read answer
fi ;;
[Dd])echo -n "answer: " ; read answer
if["$answer"="$D"]
then
echo "Correct, your password is: " $pass
else
echo "Incorrect. Choose another question to answer." ; read answer
fi ;;
[Ee])echo -n "answer: " ; read answer
if["$answer"="$E"]
then
echo "Correct, your password is: " $pass
else
echo "Incorrect. Choose another question to answer." ; read answer
fi ;;
done
esac
esac
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Saint Louis University, Baguio City, Philippines, Ms. Castillo, IT 222
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).