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.

Python03
  • 79
  • 1
  • 2
  • 10
  • Looking at the [docs](https://docs.python.org/3.1/library/getpass.html) 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.** – toti08 Aug 15 '18 at 15:44
  • @toti08 Thanks! now I know – Python03 Aug 15 '18 at 15:48

2 Answers2

5

You can use the following library to do so

import getpass

pswd = getpass.getpass('Write your password here:')
print(pswd)
Arghya Saha
  • 5,599
  • 4
  • 26
  • 48
-1

use getpass

like

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

nagataaaas
  • 400
  • 2
  • 13