Python getpass

This article covers the getpass library in Python

The getpass module comprises of only two functions, getpass() and getuser().

The getuser() function returns the login name of the user. This function checks the environment variables LOGNAMEUSERLNAME and USERNAME, in order, and returns the value of the first one which is set to a non-empty string.

user_name = getpass.getuser()

The getpass() function is meant to retrieve a password from the user without echoing it back to the input area. This means that while the user is typing in the password, nothing will show onscreen, thus improving the password security.

password = getpass.getpass()

Note: There may be certain conditions in which this does not work, such as the Python terminal.

This marks the end of the Python getpass library. Any suggestions or contributions for CodersLegacy are more than welcome. Relevant questions can be asked in the comments section below.

Notify of
Inline Feedbacks
View all comments