Is there a way in Python to convert characters as they are being entered by the user to asterisks, like it can be seen on many websites?
For example, if an email use
If you want a solution that works on Windows/macOS/Linux and on Python 2 & 3, you can install the stdiomask module:
pip install stdiomask
Unlike getpass.getpass() (which is in the Python Standard Library), the stdiomask module can display *** mask characters as you type.
Example usage:
>>> stdiomask.getpass()
Password: *********
'swordfish'
>>> stdiomask.getpass(mask='X') # Change the mask character.
Password: XXXXXXXXX
'swordfish'
>>> stdiomask.getpass(prompt='PW: ', mask='*') # Change the prompt.
PW: *********
'swordfish'
>>> stdiomask.getpass(mask='') # Don't display anything.
Password:
'swordfish'
Unfortunately this module, like Python's built-in getpass module, doesn't work in IDLE or Jupyter Notebook.
More details at https://pypi.org/project/stdiomask/