accepting password using kshell

accepting password using kshell

Post by Himans » Tue, 09 Sep 2003 18:59:15



Hi,
I have to accept user password using ksh and the script should echo
out "*" for every character input. I am having problem detecting the
end-of-password ( when the user presses the enter key)

Here is the script.

#!/bin/ksh
echo "enter password:\c "
ch="";
pass="";

stty -echo
stty raw

while [[ "$ch" != "x" ]];  ## i need to catch the newline here instead
of 'x'
do
        pass=${pass}${ch}
        ch=`dd bs=1 count=1 2> /dev/null`
        print -n "*"
done
stty -raw
stty echo

echo "the password is "$pass

 
 
 

accepting password using kshell

Post by Ed Morto » Tue, 09 Sep 2003 20:56:44



> Hi,
> I have to accept user password using ksh and the script should echo
> out "*" for every character input. I am having problem detecting the
> end-of-password ( when the user presses the enter key)

> Here is the script.

> #!/bin/ksh
> echo "enter password:\c "
> ch="";
> pass="";

> stty -echo
> stty raw

> while [[ "$ch" != "x" ]];  ## i need to catch the newline here instead
> of 'x'

I've never done this so I may be way off, but have you tried all of these:

while [[ "$ch" != "\n" ]]

nl="\n"
while [[ "$ch" != "$nl" ]]

nl="
"
while [[ "$ch" != "$nl" ]]

Regards,

        Ed.

 
 
 

accepting password using kshell

Post by Dan Merce » Wed, 10 Sep 2003 00:17:14


: Hi,
: I have to accept user password using ksh and the script should echo
: out "*" for every character input. I am having problem detecting the
: end-of-password ( when the user presses the enter key)
:
: Here is the script.
:
: #!/bin/ksh
: echo "enter password:\c "
: ch="";
: pass="";
:
: stty -echo
: stty raw
:
: while [[ "$ch" != "x" ]];  ## i need to catch the newline here instead
: of 'x'

First,  the LHS of a conditional expression,  or the single parameter of a
conditional expression option,  never needs to be quoted.

So

    [[ $x = "$y" ]]

and

    [[ -z $x ]]

will never fail unexpectedly.

Second,  IFS is NEVER inherited in ksh (that was an old security hole
with setuid scripts.  Although setuid scripts are widely disallowed,  the
fix remains.  For instance,  with a setuid Bourne sh script you could
set IFS=/ to plant a trojan if the PATH was not explicitly set in the script).
So IFS,  unless explicitly changed,  is space-tab-newline.  So you can get
a newline character by stripping off the first two characters:

    nl=${IFS#??}

However,  in raw mode,  the character you want to be looking for is
carriage return:

    cr="$(print -n "\r")"

Dan Mercer

: do
:         pass=${pass}${ch}
:         ch=`dd bs=1 count=1 2> /dev/null`
:         print -n "*"
: done
: stty -raw
: stty echo
:
: echo "the password is "$pass

 
 
 

1. smbclient asks for password but never accepts the password entered.

I'm using the "DIAGNOSING YOUR SAMBA SERVER" document by Andrew Tridgell to
track down the problem(s) with my server.  This well writen document has ten
steps.  The third is to issue the command: smbclients -L SERVERNAME.

When I issue the above command I see the ip addresses for both my networking
cards (My server has IP Masq. working) and then it asks me for a password.
?!
No mater what I enter or if I just press return without entering anything it
tells me that the password is bad.

The document says that the guest account may not be valid and suggests:
"Check what your guest account is using "testparm" and temporarily remove
any "host allow", "hosts deny", "valid users" or invalid users" lines."

I don't understand what he wants me to check on the "guest account" and none
of those lines exist in my smb.conf file.

Any help out there??

Thanks

2. Kernel problem.

3. change password policy to accept very simple passwords

4. Installing perl 5

5. Can the accept() be used after using one successful connect() with the same TCP port ?

6. ftpd where?

7. deleting records in a file using AWK, SED, or kshell

8. 2.4.19: can't compile SiS graphical card support

9. ERROR: KDE shadow password error although no shadow passwords used

10. wu-ftpd does not accept password with special characters

11. ascii char not accepted as password in X

12. Sol. 2.6 passwd won't accept any new passwords

13. Red Hat 5.1won't accept password