?

Log in

No account? Create an account

Previous Entry | Next Entry

Reading passwords in shell script

There is an option with "read" to read the passwords, here is a small shell script stating that.
When the script prompt to enter the password, and user type the password it won't be displayed on the screen.

 $ cat passwwd.sh
#!/bin/sh

ACTUAL="jksaikia"
read -s -p "Password: " enteredpass
echo ""

[ "$enteredpass" == "$ACTUAL" ] && echo "Accepted" || echo "Sorry"

$ ./passwwd.sh
Password:
Accepted

$ ./passwwd.sh
Password:
Sorry

This can be achieved using "stty" also as shown below:

old_set=`stty -g` #store original state of stty
echo -n "Password: "
stty -echo #turn off echoing
read password
stty echo #To restore the echoing
echo ""
echo "You entered $password"
stty $old_set #set original state
 

Profile

jaduks
Jadu Kumar Saikia

Latest Month

January 2008
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
2728293031  
Powered by LiveJournal.com
Designed by chasethestars