3

I am trying to make a small program which checks the strength of the user password. When the user is prompted to enter their password I want the input to show as asterisks or dots instead of the text input. Is there a way of hiding this input.

I have used getpass to try and hide the input without success.

    from getpass import getpass
    passwd = getpass('Please enter your password')

This gives me the following warning message:

Warning (from warnings module): File "C:\Program Files (x86)\Python36-32\lib\getpass.py", line 100 return fallback_getpass(prompt, stream) GetPassWarning: Can not control echo on the terminal. Warning: Password input may be echoed. Please enter your password: this_is_my_password

The password is entered on the line but instead of coming up with astrisks it comes up with the original characters.

As the program will check the strength of the password I need to have something that does not save the password as the asterisks but as its original characters.

As well as this is there any way of incorporating a way of showing the user password if they perform an action. I was considering using a button but that is an area in Python I am not confident with so could I program in another way with a specific key.

Sudo code for project.

userPass = hidden(input("Please enter your password "))
if showPassword selected:
    show the password
else:
    move on with the rest of the program
Jake Symons
  • 468
  • 2
  • 10
  • 19
  • 1
    This question may answer yours https://stackoverflow.com/questions/35805078/how-do-i-convert-a-password-into-asterisks-while-it-is-being-entered/35805111 – dangee1705 Nov 07 '17 at 20:52
  • 1
    That's not an error, it's a warning. One of the differences is that warnings are informative, but not disruptive; a program doesn't stop running after a warning. Seems like what you have could still work; keep poking at it. – Eric Ed Lohmar Nov 07 '17 at 21:05
  • 2
    What environment are you running this program in? Whatever it is, it lacks some feature that `getpass()` uses to hide character echo. If you're running the code from inside an IDE of some sort, try running it directly from the command line instead. – jasonharper Nov 07 '17 at 21:31
  • i can make a customize input function with pyHook, pythoncom, sys and pysignal modules, do you like it ir not? – DRPK Nov 07 '17 at 22:19
  • @jasonharper Still having the same problems. I am running this in 3.6.2 IDE. I have tried running it in the shell and the same warning messages appears. – Jake Symons Nov 08 '17 at 18:25

2 Answers2

2

The warning basically means you are running your program in an environment where Python cannot use the regular interactive IOCTL calls to implement the asterisks-only functionality. Running a program from inside your IDE basically causes the IDE to run the program in a pseudo-terminal. Try running it on the command line instead.

tripleee
  • 175,061
  • 34
  • 275
  • 318
1

The getpass module contains a getpass function that works just like input(), except that it turns the terminal echo off.

The result is the password entered, which you can use to determine its strength or print as needed, but while the user is entering their password, nothing is printed except the prompt.

>>> from getpass import getpass
>>> passwd = getpass('Please enter your password')
Please enter your password
>>> print passwd
This is my password
3Doubloons
  • 2,088
  • 14
  • 26