5

I want to ask what changes we can make to our input function so that whatever we type as input is represented as a '*'.As we all have seen that when we type a password on the login page it gets written as ******* .Can this be done in python? something like this:

Python 3.6.6 (v3.6.6:4cu1f74eh7, Jun 27 2018, 02:47:15) [MSC v.1900 64 bit 
(Intel)] on win64
Type "copyright", "credits" or "license()" for more information.
>>> a = input('Write your password here:')
Write your password here: ************* # we write our password
>>> print(a)
stackoverflow

The getpass is not working and giving a warning too.

2
  • Looking at the docs you can read that If echo free input is unavailable getpass() falls back to printing a warning message to stream and reading from sys.stdin and issuing a GetPassWarning. Commented Aug 15, 2018 at 15:44
  • @toti08 Thanks! now I know Commented Aug 15, 2018 at 15:48

2 Answers 2

5

You can use the following library to do so

import getpass

pswd = getpass.getpass('Write your password here:')
print(pswd)
Sign up to request clarification or add additional context in comments.

2 Comments

Why isn't it doing anything
It is hiding the input and when you press enter then it is printing the input you made
-1

use getpass

like

import getpass s = getpass.getpass("Write your password here:") Write your password here: # input will be hidden

1 Comment

Please note that @argo already provided a similar answer, avoid adding duplicates.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.