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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding password entry

Status
Not open for further replies.

Einstein47

Programmer
Nov 29, 2001
737
US
I have a script that I wrote so that a user could change his/her CVS password. Currently I just do the following when they enter the password:
Code:
echo "Enter your current password: \c"
stty -echo
read oldpass
stty echo
This works except that the users complain that they like to see astericks (****) when they type to know how many characters they have typed.

Is there an easy way to do this (without creating my own read program)?

Thanks, Einstein47
("If computers ever get too powerful, we can organize them into a committee - that will do them in." - Unknown)
 
Don't think so - your users are too used with Windows - I would try to convince them of the benefits of not echoing an * - the point of this (it's the standard on Unix) is so people *don't* know how many characters you typed.

Not much help ... but I will have a think about it :)

Greg.
 
Hi Einstein:

First, I agree with Greg; Try to talk the users out of it.

Second, if you're still forced to do this, I had a similar situation several years ago. I ended up writing a ksh function (used in another tek-tips thread) that gets one character from the terminal. I figured out where on the screen the user types the password, and then alternately get a key, reposition the cursor, and get a another character. I terminate if the CR is pressed or greater than 10 characters are input.

It works, but it's a kluge; You do what you can.

Regards,

Ed

#!/bin/ksh
tput clear

# set the cursor position.
function set_pos {
tput cup $1 $2
}

# get a character with echo and interrupt disabled.
function readkey {
local anykey oldstty

oldstty=$(stty -g)
stty -icanon -echo min 1 time 0 -isig
anykey=$(dd bs=1 count=1 <&0 2>/dev/null)
stty $oldstty
echo $anykey
}

lines=0
cols=15
printf &quot;Get password: &quot;
x=0
while true
do
set_pos $lines $cols
anychar=$(readkey)
((x=x+1))
((cols=cols+1))
[[ -z $anychar ]] && break # break if CR
password=$password&quot;$anychar&quot;
echo &quot;*&quot;
((x > 10)) && break # break if greater than 10 characters
set_pos $lines $cols
done

printf &quot;\n%s\n&quot; $password
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top