Find the answer to your Linux question:
Results 1 to 8 of 8
I want to hide the entered key from keyboard like when i enter password it shows me *, so how can i do this by programming.I am taking username and ...
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    3

    Smile hiding keyboard input

    I want to hide the entered key from keyboard like when i enter password it shows me *, so how can i do this by programming.I am taking username and password from user and i want to hide password by printing * when entering password.
    Help!!!!

  2. #2
    Linux User nalg0rath's Avatar
    Join Date
    Sep 2004
    Location
    Stockholm
    Posts
    303
    What programming language are you using?

  3. #3
    Just Joined!
    Join Date
    Oct 2006
    Posts
    47
    use Xlib Programming

  4. #4
    Linux User nalg0rath's Avatar
    Join Date
    Sep 2004
    Location
    Stockholm
    Posts
    303
    Quote Originally Posted by hiimsa View Post
    use Xlib Programming
    Well that does not solve any problem does it? First of all if you are going to use Xlib you need X Window System and also you need to be programming in C (or in a language that can use C-libs).

    He could use Ncurses if he wanted or he could write the whole thing by himself but we can't just tell him what to use unless we know what programming language he is using or if he wants a graphical application.

  5. #5
    Just Joined!
    Join Date
    Jun 2007
    Posts
    3
    Quote Originally Posted by james_rahul2002 View Post
    I want to hide the entered key from keyboard like when i enter password it shows me *, so how can i do this by programming.I am taking username and password from user and i want to hide password by printing * when entering password.
    Help!!!!
    I AM USING SHELL SCRIPTING... I JUST WANT * ON PRESSING ANY KEY FROM KEYBOARD..JUST GIVE ME LINUX COMMAND I WILL INTEGRATE THAT COMMAND IN MY SCRIPT

  6. #6
    Just Joined!
    Join Date
    Jun 2007
    Posts
    3

    Smile hiding .....

    I Am Using Shell Scripting... I Just Want * On Pressing Any Key From Keyboard..just Give Me Linux Command I Will Integrate That Command In My Script

  7. #7
    Linux User nalg0rath's Avatar
    Join Date
    Sep 2004
    Location
    Stockholm
    Posts
    303
    Okay, I wrote a little script to get you started:
    Code:
    #!/bin/sh
    stty_orig=`stty -g`
    stty -icanon -icrnl -echo min 0 time 0
    key=""
    password=""
    while [ "$key" != <ENTER KEYCODE> ]
    do
      key=""
      while [ "$key" = "" ]
      do
        read key
      done
      if [ "$key" != <ENTER KEYCODE> ]
      then
        echo -n "*"
        password=$password$key
      fi
    done
    stty $stty_orig
    You will need to replace the <ENTER KEYCODE> with the correct "character" that represents a keypress of the [Enter] key. This is usually ^M, but I'm not sure if that always works.

    This is just to get you started, it gets much more complicated when you need such functions as you should be able to erase characters.

  8. #8
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    nal's script is correct, but do you need it to print *s? Most Linux apps just print nothing at all, and if you're okay with that, the script becomes FAR FAR simpler. The easiest way would be to do:
    Code:
    #!/bin/bash
    
    stty_orig=$(stty -g)
    echo -n "Enter Your Password: "
    stty -echo
    read password
    stty $stty_orig
    
    echo "Your password is: $password"
    The only complex thing here is the use of 'stty', which allows you to control the terminal. Here, we turn off the printing of characters entirely, enter the password, and then re-enable it. This way, you do not need to manually print characters or read them one-by-one or anything like that. It just works.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...