Member Avatar


Hi, all.

I am having a problem using the getpass() function, there are no problems with the raw_input(), though.
I'm trying to check the user input is valid (meaning that the Username is nav and the password is 39429432)
Really, I DON'T want to use raw_input() for the password field.

def login():
    import getpass
    userpass = "39429432" = "nav";
    usr = raw_input('Username:   ')
    psswd = getpass.getpass(["prompt"["stream"]])
    if usr==usernm and psswd==userpass:

This code D:

Here's the error:

Traceback (most recent call last):
  File "C:\Users\Navid_2\Desktop\", line 5, in login
    psswd = getpass.getpass(["prompt"["stream"]])
TypeError: string indices must be integers, not str

You must learn to read the python documentation. getpass.getpass([prompt[stream]]) in the documentation's notations means that you can call getpass one of the following ways

getpass.getpass(prompt, stream)

prompt is a string, and stream is a file object.

Member Avatar



It works fine when opened in a terminal window, but not in IDLE, or Komodo IDE, or any other IDE I am assuming. The following warning is displayed:

Warning (from warnings module):
  File "C:\Python27\lib\", line 92
    return fallback_getpass(prompt, stream)
GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.

The program runs, but it does what it says :(
Password is echoed.

This will work

from easygui import passwordbox
password = passwordbox("What is your password ?")

You must install easygui first (pip install easygui in a terminal).

commented: Don't reinvent the wheel hacker ;-) +12