Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ENTERING PASSWORD: ****** ???

1 view
Skip to first unread message

Joseph Suriol

unread,
Jan 20, 1999, 3:00:00 AM1/20/99
to
The script

print
stty -echo
read -r pw?"Enter password: "
stty echo
print

does the job. But, is there a way to have an asterisk appear for each
password character typed?

It is easy in C putting the terminal in cbreak mode, but in ksh seems
impossible.

I am using ksh93

Thanks

Dan Mercer

unread,
Jan 20, 1999, 3:00:00 AM1/20/99
to
In article <785fad$qr9$1...@winter.news.rcn.net>,

read will only return after getting a newline. The -r option only
affects how backslash-newline sequences are to be treated, it does
not do a raw read.

You could either:

function savetty
{
SAVETTY=$(stty -g </dev/tty)
}

function rawtty
{
stty raw -echo </dev/tty
}

function cookedtty
{
stty ${SAVETTY:-cooked} </dev/tty
}

function getpass
{
typeset
savetty
rawtty
typeset -n passwd=${1:-PASSWD}
typeset ans
while :
do
ans=`dd if=/dev/tty count=1 bs=1 2>/dev/null`
case $ans in
$'\n') break;;
$'\b') [[ -n $passwd ]] && {
passwd="${passwd%?}"
print -n "\b \b"
}
;;
*) passwd="${passwd}${ans}";print -n "*";;
esac
((${#passwd}>8)) && { print -n "\a";break; }
done

cookedtty
}

[[UNTESTED]]

or create a builtin


Dan Mercer

dame...@uswest.net

Opinions expressed herein are my own and may not represent those of my employer.


John DuBois

unread,
Jan 22, 1999, 3:00:00 AM1/22/99
to
In article <785fad$qr9$1...@winter.news.rcn.net>,

Joseph Suriol <tig...@usa.net> wrote:
>The script
>
>print
>stty -echo
>read -r pw?"Enter password: "
>stty echo
>print
>
>does the job. But, is there a way to have an asterisk appear for each
>password character typed?
>
>It is easy in C putting the terminal in cbreak mode, but in ksh seems
>impossible.

If the OS you're using has a facility equivalent to mapchan, try that.
I use e.g.

[set up traps to unmap channel on interrupt]
mapchan -f hide.map
read -r password
mapchan -n

where hide.map contains:

# Erase, newline, cr, and ^G are not hidden because the shell may emit them.
output
1 '*'
2 '*'
3 '*'
4 '*'
5 '*'
6 '*'
7 7
8 8
9 '*'
10 10
11 '*'
12 '*'
13 13
14 '*'
...
255 '*'

John
--
John DuBois spc...@armory.com. KC6QKZ http://www.armory.com./~spcecdt/

0 new messages