Computer Science Atlas
Snippets

Python 3: Password Input Prompt

March 30, 2022
 
Table of Contents

Using getpass

On all versions of Python 3, we can use the getpass module from the built-in Python Standard Library to prompt the user to enter a password.

The user's password will not show up on-screen while the user is typing it.

from getpass import getpass

password = getpass( 'Password: ' )
1
2
3
from getpass import getpass

password = getpass( 'Password: ' )

We can replace 'Password: ' in the code above with any message that we want to show before the password input cursor.

See Also

Reference