Home >Backend Development >Python Tutorial >How Can I Get Concealed Password Input in Python?

How Can I Get Concealed Password Input in Python?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-25 00:45:11154browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn