Home >Backend Development >Python Tutorial >How Can I Get Concealed Password Input in Python?
Obtaining a Concealed Password Input in Python
Similar to Linux's concealed password input during sudo operations, it is possible to hide the user's password input in Python. This is particularly useful when dealing with sensitive information that should remain confidential during data entry.
To achieve this in Python, utilize the getpass.getpass() function. This function allows the user to enter a password without revealing the characters typed:
from getpass import getpass password = getpass()
Optionally, a custom prompt can be provided as an argument. By default, the prompt "Password: " is displayed. It's important to note that getpass.getpass() relies on a proper terminal to disable character echoing. Therefore, it may not function correctly within environments such as IDLE.
The above is the detailed content of How Can I Get Concealed Password Input in Python?. For more information, please follow other related articles on the PHP Chinese website!