I have created a simple login program using python, I would like it to display stars or dashes when the user enters a password instead of displaying numbers.
I have created a simple login program using python, I would like it to display stars or dashes when the user enters a password instead of displaying numbers.
If you just want to avoid echoing the input - you can use a python standard library called getpass- in it, there is a function called getpass which hides the user input:
from getpass import getpass
password = getpass()
Note that getpass requires a proper terminal, so it can turn off the echoing of typed characters.
If you wish to display stars when the user enters a password, you can install the pwinput module:
pip install pwinput
For example:
>>> pwinput.pwinput()
Password: ********
'password'
You can also change the mask character:
>>> pwinput.pwinput(mask='X') # Change the mask character.
Password: XXXXXXXX
'password'
And you can also change the prompt:
>>> pwinput.pwinput(prompt='PW: ', mask='*') # Change the prompt.
PW: ********
'password'
The PWInput module is able to display characters as you type.
>>> import pwinput
>>> pwinput.pwinput() # Show * for each typed character.
Password: *********
'swordfish'
>>> pwinput.pwinput(prompt='PW: ') # Show a custom prompt.
PW: *********
'swordfish'
>>> pwinput.pwinput(mask='X') # Show a different character when user types.
Password: XXXXXXXXX
'swordfish'
>>> pwinput.pwinput(mask='') # Don't show anything when user types (falls back and calls getpass.getpass()).
Password:
'swordfish'
Have a look! https://pypi.org/project/pwinput/1.0.1/