Encrypt password but use * when typing password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Encrypt password but use * when typing password
# 8  
Old 06-30-2011
Hi,

Thanks for all the replies.

I will try to work on it.

Thanks
Dinesh

---------- Post updated at 10:19 AM ---------- Previous update was at 02:04 AM ----------

Hi

I am able to solve the issue of getting the password in '*' and displaying it. But I landed up in another issue. When I press backspace it does not go back and erase the character but instead it puts a '[]' type

Code:
password:********
the password is wel[]come

In the above I typed a backspace near letter 'l' but it has put a box like symbol.

But this problem goes if I type ^H character

Code:
[ncoadmin@netcool ~]$ ./a.sh
password:******
the password is wecome

The modified code looks like this

Code:
#!/bin/sh
exec 4>/dev/tty
function getpass
{
        typeset prompt=$1
        typeset backspace=$(echo -en \\b\\c)
        typeset enter=$(echo -e \\r\\c)
        typeset savesetting=$(stty -g)
        typeset keystroke password n i reading result
        n=0
        echo -e "${prompt}"\\c >&4
        stty -echo -icrnl -icanon min 1 time 0
        reading=1
        while ((reading)) ; do
                keystroke=$(dd bs=1 count=1 2>/dev/null)
                case $keystroke in
                $enter)
                        reading=0
                        ;;
                $backspace)
                        if ((n)) ; then
                                echo -e "${backspace} ${backspace}"\\c >&4;
                                #stty erase '^H'
                                ((n=n-1))
                        fi
                        ;;
                *)
                        echo -e \*\\c >&4
                        data[n]=$keystroke
                        ((n=n+1))
                esac
        done
        stty "$savesetting"
        echo -e >&4
        result=""
        i=0
        while  ((i<n)) ; do
                result="${result}${data[i]}"
                ((i=i+1))
        done
        echo -e $result
        return 0
}
final=$(getpass "password:")
echo -n  the password is $final
exit 0

Please let me know what should I modify so that when the user presses the backspace I should erase a character

Thanks
Dinesh
# 9  
Old 06-30-2011
You don't need to change all your echo commands to "echo -e" or "printf" just set the following at the top of your script (line 1):

Code:
shopt -s xpg_echo

For backspace issue just use
Code:
stty erase ^\?

perhaps this should be in your .profile or .bash_profile

Last edited by Chubler_XL; 06-30-2011 at 11:28 PM..
# 10  
Old 07-01-2011
Hi

I tried to modify and run the code but it does not seem to work. The backspace works only if I press the ctrl+H key only. It does not recognize when I press the 'backspace' key.

Just wanted to know what else should I modify? So, that the backspace key works.

Thanks
Dinesh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Encrypt and Decrypt a File with Password

Hello, I have few files on unix which are payroll related and I need them to encrypt with password so others wouldn't see the data. I use ETL tool and would like to know the unix command that does encryption/decryption to use in the ETL. Thank you, Sri (3 Replies)
Discussion started by: eskay
3 Replies

2. Shell Programming and Scripting

Encrypt Plaintext Password?

How do I encrypt a plaintext password that I need hardcoded in a bash script? (3 Replies)
Discussion started by: wyclef
3 Replies

3. Shell Programming and Scripting

Encrypt DB password in Script

Hi, I have a SQL which i want to run through a shell script. query_result=`/home/oracle/product/11.2.0/bin/sqlplus -S uname/pwd@DBNAME <<! set heading off feedback off trimspool on set pagesize 0 set linesize 9999 spool $PARAM_PATH/param_name.txt; Select sysdate from dual; spool off;... (6 Replies)
Discussion started by: chetan.c
6 Replies

4. AIX

SSH session closes after typing correct password

hi guys need some help. when ever i'm login ssh to aix server session always closed. when trying t0 type wrong password the session still continues, but we tried the correct password it automatically ends. what could be the problem to this please see .profile details ... (6 Replies)
Discussion started by: bocha
6 Replies

5. Shell Programming and Scripting

How to Encrypt password

Hello, I have a paramter file, In which I store all the user-ids and passwords for the project. So if a user just invokes the paramter file he has access to all the variables, which i have exported in the parmatere file. Now if a user echo's the variable which stores the databse password.... (1 Reply)
Discussion started by: DSDexter
1 Replies

6. Shell Programming and Scripting

Encrypt and save password

Hello all, I need to encrypt and save a password in a file and later decrypt to determine the original password string. Please suggest how can I use the linux commands or other approach to accomplish this. Thanks for your help. (1 Reply)
Discussion started by: cheerful
1 Replies

7. Shell Programming and Scripting

cronjob on a remote ssh without typing password

Hi there, How can I send a script to a remote ssh client. 1) I cannot connect through ftp 2) I just need to read a file on a remote server. Here is what I do: ~$ ssh santiago@myserver.com santiago@myserver.com's password: santiago@myserver:~$ cat logfile hello world bonjour le monde hola... (1 Reply)
Discussion started by: chebarbudo
1 Replies

8. UNIX and Linux Applications

How to encrypt oracle password table ?

Hi Oracle & Unix expert, Could you tell me how to encrypt oracle table ? Thanks. (1 Reply)
Discussion started by: olaris
1 Replies

9. Shell Programming and Scripting

encrypt and decrypt password

how do i encrypt and decrypt a password (2 Replies)
Discussion started by: sanwish
2 Replies

10. Programming

hide password typing

I am doing a project in C program which requires to type in password in Unix terminal. Does anybody know how to shade or not output any words typed by user in the terminal? I use the function scan() to read typing from user. Thanks in advance. (2 Replies)
Discussion started by: ivancheung
2 Replies
Login or Register to Ask a Question