i am trying to write shell script
how to write shell script which is ask for user id and password then compare both from two different file..
i have no idea how to compare with data present in file..
#!/bin/bash -e
read -p "User ID: " first
read -p "Password: " second
if [ X$first = X$second ];then
echo "Both Values are equal"
else
echo "Mismatch"
fi
You will have to extract the information from the two files:
#! /bin/bash -e
read -p "User ID: " userid
stty -echo
read -p "Password: " password
stty echo
userkey=$(getuserkey "${userid}")
userpwd=$(getuserpwd "${userkey}")
if [[ -n "${userkey)" -o "${password}" != "${userpwd}" ]]; then
echo Invalid username or password
exit 1
fi
(shell psuedo-code, untested!)
Please keep in mind that both files would have to be readable by all users of this script, and the "password" would be stored as cleartext. You could set the script to run setuid, but that could raise other security issues. Perhaps man sudo (All) could be used to validate access, just have the script run: