
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python getpass Module
There are two functions defined in getpass module of Python’s standard library. They are useful whenever a terminal based application needs to be executed only after validating user credentials.
getpass()
This function prompts the user to enter a password. By default the keys entered by user in the terminal are not echoed. Also the default prompt that appears on terminal is ‘password’ which can be customized by providing a string as parameter.
In following example, Python prompt is invoked from Command prompt terminal on Windows. The password entered is not echoed in the terminal.
C:\python36>python Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import getpass >>> pwd=getpass.getpass("enter pssword:") enter pssword: >>> pwd 'admin'
However, if IDLE software is used for interactive session of Python, it doesn’t provide echo free input. Hence password entered is echoed.
getuser()
This function returns login name of the user.
>>> getpass.getuser() 'acer'
- Related Articles
- getpass() and getuser() in Python (Password without echo)
- HandCalcs Module Python
- Fraction module in Python
- colorsys module in Python
- Import module in Python
- Keyboard module in Python
- struct module in Python
- Pygorithm module in Python
- __future__ Module in Python
- Explain calendar module in python?
- The time Module in Python
- The calendar Module in Python
- The Threading Module in Python
- Python - Working with .docx module
- Import a module in Python
