1

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
  • 39
  • 1
  • 1
  • 9
  • 7
    Possible duplicate of [Getting command-line password input in Python](https://stackoverflow.com/questions/9202224/getting-command-line-password-input-in-python) – Daria Pydorenko Aug 15 '18 at 15: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

3 Answers3

1

You can use the following library to do so

import getpass

pswd = getpass.getpass('Write your password here:')
print(pswd)
argo
  • 4,780
  • 3
  • 21
  • 40
0

use getpass

like

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

Yumm 114514
  • 314
  • 1
  • 10
0

You can use the getpass module in python.

a = getpass.getpass("Write your password here:")

When you do the above you'll get the following:

Write your password here: #No Characters Shown

You can however write a function to store the entered text and report only a string of *'s when called. Kinda like this, which I did not write

Anidh Singh
  • 182
  • 1
  • 5
  • 17