calling user input in bash script
Hi all
I have written a bash script and basically it asks the user to enter a username and a password. eg: echo "please enter username and press [enter]: " read username echo "please enter password and press [enter]: " read password What I am trying to do is change the characters that come up when the input is typed. in this situation the input from the user comes up as it is typed. eg. username tom shows as tom and password 123456 comes up as 123456. I would like to change the password to come up as hashes instead of the actual password. has anyone tried to do this? |
Hashes I don't know but with 'read -s' at least they're not echoed.
|
You have to change the terminal settings to do this. Using stty you can disable the canonical mode and disable the local echo (this is the same effect of read -s suggested by unSpawn). Then you can detect key strokes using the dd command and put the character corresponding to each key into the password. Echo a single asterisk (or a hash, if you prefer) and repeat until the user hits Enter. Finally restore the original settings and have the "recorded" password at your disposal.
Code:
#!/bin/bash |
thanks for the details, thats exactly what I was after. :-)
|
All times are GMT -5. The time now is 08:38 PM. |