1834152 Members
2291 Online
110064 Solutions
New Discussion

Re: Simulate login.

 
SOLVED
Go to solution
Kenny Chau
Trusted Contributor

Simulate login.

Hi all,

I would like to write a shell script which will simulate login include login prompt and password prompt and then it will compare the password table (self create), if matched, continue; if not match, exit. How can I do that? Also, how to make the password invisible while typing the password? or subsitute by *?

Many thanks.
Kenny.
Kenny
3 REPLIES 3
Deepak Extross
Honored Contributor
Solution

Re: Simulate login.

Kenny,

You can turn off echo using stty.
This should start you off:

echo "Login :\c" read user echo "Password :\c" stty -echo
read pass
stty echo

echo You entered $user $pass
Deepak Extross
Honored Contributor

Re: Simulate login.

Oops..formatting problems.

echo "Login :\c"
read user
echo "Password :\c"
stty -echo
read pass
stty echo

echo You entered $user $pass


p = grep $user | cut -f2
// assuming that username and password are stored in a pipe-delimited format in

if [ $pass = $p ]
then
// do your stuff here
else
exit -1
fi
Kenny Chau
Trusted Contributor

Re: Simulate login.

Thanks Deepak, you had got what I want.

Thanks very much.
Kenny.
Kenny