I need to write a code for an input password, like when I need to type the password it needs to layer the password like this *****. Notice that to code I'm using PyCharm.
Asked
Active
Viewed 1.0k times
2
-
https://stackoverflow.com/a/9202236/9415337 – miquelvir Apr 07 '21 at 15:47
-
3Does this answer your question? [Getting command-line password input in Python](https://stackoverflow.com/questions/9202224/getting-command-line-password-input-in-python) – miquelvir Apr 07 '21 at 15:47
2 Answers
6
There is no easy way to do this. However, you can use a couple of modules to create a similar function.
- PYAUTOGUI
import pyautogui
paswrd = pyautogui.password(text='', title='', default='', mask='*')
This opens a small window in which you can enter your password. Here, the password will be displayed as you want: it will use *
s.
- GETPASS
import getpass
paswrd = getpass.getpass()
This will allow the user to enter a password normally, and the password won't show. It will be hidden. THIS ONLY WORKS IN THE TERMINAL, NOT SHELL

The Pilot Dude
- 2,091
- 2
- 6
- 24
2
You can use the getpass
module to hide your password:
from getpass import getpass
password = getpass(prompt='Input your password: ') # the default prompt is 'Password: '
This won't replace it with *
but at least you can't see the password.
Note: It will not work in the shell. Thanks to @PilotDude

Have a nice day
- 1,007
- 5
- 11
-
However, it should be noted that getpass doesn't work in the shell. – The Pilot Dude Apr 07 '21 at 15:49
-
If using Spyder IDE, you'll get the following warning: QtConsole does not support password mode, the text you type will be visible. – Ben Mar 02 '22 at 15:58
-