Thread: Password input?

    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    11

    Password input?


    How would I make the something inputed appear when being typed as * symbols, like a normal login deal.
    I need to input passwords in a cmd line app I'm writing.
    Thanks.
    Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes!
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    For a Windows console you can use the getch()/putch() pair found in the msvcrt module.

    For Linux try the termios module. There is an example in it's documentation for password handling. Basically, this module allows you to switch options of the terminal the python app is running in.

    Grim
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    11
    Or you could use the 'getpass' module. It seems it'll autodetect what you need with the getpass.getpass() function.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    11
    Alright, I'll try that.
    Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes!
  8. #5
  9. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    That just seems too easy, there must be a catch
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Believe it or not, no catch that i can see .. tested and retested.. as long as you don't run though IDLE (which gives you a warning message) you wont see anything user enters! Kinda an invisable version of raw_input(), and very cross platform!

    A lil example, but too basic to be of any real use though!

    Code:
    import getpass
    
    passwd = getpass.getpass('enter your password')
    
    raw_input('Press ENTER to show the password..')
    
    print passwd
    
    raw_input('Press ENTER to exit..')
    Nicely spotted Perc

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo