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

How to print ******'s to stout instead of "stty -echo"

13 views
Skip to first unread message

rtb...@kcc.fsa.usda.gov

unread,
Dec 15, 1997, 3:00:00 AM12/15/97
to

I'd like to be able to somehow print asterisks or whatever to the screen
like gui apps do when someone is entering a password. Is this
possible???

-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet

Barry Margolin

unread,
Dec 16, 1997, 3:00:00 AM12/16/97
to

In article <882233260....@dejanews.com>,

<rtb...@kcc.fsa.usda.gov> wrote:
>I'd like to be able to somehow print asterisks or whatever to the screen
>like gui apps do when someone is entering a password. Is this
>possible???

I don't think you can do it easily in a shell script. A C or Perl program
could put the terminal in raw mode and echo *'s. The program would also
have to handle input editing itself.

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.

Surya V. Avantsa

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

Surya V. Avantsa wrote:
>
> rtb...@kcc.fsa.usda.gov wrote:
> >
> > I'd like to be able to somehow print asterisks or whatever to the screen
> > like gui apps do when someone is entering a password. Is this
> > possible???
> >
> > -------------------==== Posted via Deja News ====-----------------------
> > http://www.dejanews.com/ Search, Read, Post to Usenet
>
> In your shell script, you could enter stty -echo
> This command will turn of echo of user input. Then after the password
> entry part is over, say stty +echo. Ex:
>
> echo 'Please enter your password:'
> stty -echo
> read $passwd
> stty +echo
> ...
>
> ...
Infact this method has an advantage over the windows gui method. In the
windows gui method, when the ** are being displayed, atleast the
stealthy on-looker would know the number of characters in your password.
Whereas in this unix method of stty -echo, the cursor simply does not
move, nor does it display anything on the screen.

Hope that helps. Pls. let me know if it worked.

Surya V. Avantsa

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

Daryl Johnson

unread,
Dec 17, 1997, 3:00:00 AM12/17/97
to

rtb...@kcc.fsa.usda.gov wrote:
>
> I'd like to be able to somehow print asterisks or whatever to the screen
> like gui apps do when someone is entering a password. Is this
> possible???

Yes, it is... Here is some ksh script to do this.


++++++++++++++ START SCRIPT ++++++++++++++
#!/bin/ksh
#Init some stuff...
pass=''
blank='false'

#Main loop executed once for each char typed...
while [ "$blank" != "true" ]
do
stty raw
c=`dd bs=1 count=1 2> /dev/null`
stty -raw

#Check for a CR.
if [ -z `echo $c | tr -d "\015"` ]
then
blank='true'
else
stty echo
echo "*\c"
pass=$pass$c
stty -echo
fi
done
+++++++++++++ END OF SCRIPT ++++++++++++

You may want to check the man pages for dd and for tr if you need
more help with this script. Feel free to email any follow up ?'s to
me at "dwj...@azstarnet.com". I will post the final answers here...

Hope this helps you out....
Dj

0 new messages