Member Avatar for HTMLperson5

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:
        main()
    else:
        SystemExit()

This code is....is....failing D:

Here's the error:

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

Recommended Answers

All 3 Replies

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()
getpass.getpass(prompt)
getpass.getpass(prompt, stream)

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

Member Avatar for HTMLperson5

getpass.getpass()

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\getpass.py", 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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.