Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

password with no echo

Tips and Tricks

password with no echo

by  vgersh99  Posted    (Edited  )
Q:
I am accepting the password from the user using 'read' command.

How can I make the password not to appear on the screen when the user is typing.

A:
# save the old terminal settings
oldmodes=`stty -g`
# disable terminal 'echo' - blind typing
stty -echo
# read user input/password
read password
# restore 'old' terminal settings
stty $oldmodes



NOTE:
Yet Another Useful Tip [YAUT] by olded [Ed]:

# readkey: This function saves the current terminal settings and
# sets the terminal to raw mode with the unix stty command. Retrieve
# 1 character with the dd command and reset original terminal settings
# with stty before returning the character to calling script.
function readkey {
local anykey oldstty

oldstty=`stty -g`
stty -icanon -echo min 1 time 0
anykey=`dd bs=1 count=1 <&0 2>/dev/null`
stty $oldstty
echo $anykey
} # end read_key

Feel free to edit as you see fit.

Regards,

Ed
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top