KSH Script Question: Passwords

KSH Script Question: Passwords

Post by Kevi » Wed, 06 Oct 1999 04:00:00



I'm trying to write a ksh script where I ask a user to enter a
password.  Is there any way to get that password to show up as asterisks
instead of literal characters.  e.g.

This is what I want to see
Password: ******

If it's not too inconvenient can you also please email me the answer at

 
 
 

KSH Script Question: Passwords

Post by Dhruv_Maheshwar » Thu, 07 Oct 1999 04:00:00


hi,

With the following script, you can hide the password while typing but
for printing stars inplace of the correct string, you have add some more
code.
try this script .....

Regards
Dhruv Maheshwari

=====================================
#!/bin/ksh

echo "Enter Password : \c"
stty -echo
read x
stty echo
echo "\n $x"

 
 
 

KSH Script Question: Passwords

Post by Huo-Pi » Thu, 07 Oct 1999 04:00:00



> hi,

> With the following script, you can hide the password while typing but
> for printing stars inplace of the correct string, you have add some more
> code.
> try this script .....

> Regards
> Dhruv Maheshwari

> =====================================
> #!/bin/ksh

> echo "Enter Password : \c"
> stty -echo
> read x
> stty echo

###Add one line.
echo $x | sed 's/./*/g'

- Show quoted text -

Quote:> echo "\n $x"

 
 
 

KSH Script Question: Passwords

Post by Matthew Land » Thu, 07 Oct 1999 04:00:00



> hi,

> With the following script, you can hide the password while typing but
> for printing stars inplace of the correct string, you have add some more
> code.
> try this script .....

> Regards
> Dhruv Maheshwari

> =====================================
> #!/bin/ksh

> echo "Enter Password : \c"
> stty -echo
> read x
> stty echo
> echo "\n $x"

Personally, I think that NOT showing stars is much better.  If someone is
watching that user log in, they will know the length of the password for that
user.  Cracking that password is now *WAY* easier.  If no stars are shown, it is
not as easy for people to detect password length.

The drawback of no stars is: if the users are true no brain users, they need
those stars to believe the password is being typed.  Many might stumble if no
output is seen on the screen.

Jst M $0.02.

 
 
 

KSH Script Question: Passwords

Post by Dan Merc » Thu, 07 Oct 1999 04:00:00




> I'm trying to write a ksh script where I ask a user to enter a
> password.  Is there any way to get that password to show up as asterisks
> instead of literal characters.  e.g.

> This is what I want to see
> Password: ******

> If it's not too inconvenient can you also please email me the answer at


Just barebones:

#!/usr/bin/ksh

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

Quote:}

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

Quote:}

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

Quote:}

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

eval $vname='$passwd'
cookedtty

Quote:}

getpass PASSWD
echo "\$PASSWD=$PASSWD"

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

 
 
 

1. ksh script problem: pwd works differently for ksh then linux binary file

Hi,

I have a pdksh installed on Linux RedHat 6.2.
From an interactive shell, when I type pwd in a directory which is a link,
I get the directory name (not hte one linked to), as I expect.
When /bin/pwd is run, I get the linked directory name !
from a ksh script, it seems it will always run /bin/pwd for pwd rather
then the ksh implementation.
Any one knows how to override this problems in ksh scripts to it will run
the pwd of the ksh command ?

thanks,
Shai

--
Posted via CNET Help.com
http://www.help.com/

2. ncr53c810 and Seagate TapeStore 8000

3. ksh 1, perl 2 - ksh or perl for scripting?

4. Exabyte 8mm and FreeBSD

5. ksh script question again

6. SUN USER GROUP EAST COAST CONFERENCE & EXHIBITION, JUNE, BOSTON

7. ksh script question

8. LUM 4.5.1 license server problem

9. File access in ksh script question.

10. how-to ksh script question

11. KSH - Newbie question... ~/ in a script

12. ksh script question - removing comments

13. AIX/KSH scripting question