2

I need to write a code for an input password, like when I need to type the password it needs to layer the password like this *****. Notice that to code I'm using PyCharm.

enter image description here

bad_coder
  • 11,289
  • 20
  • 44
  • 72
PyCharmGivesHope
  • 21
  • 1
  • 1
  • 3
  • https://stackoverflow.com/a/9202236/9415337 – miquelvir Apr 07 '21 at 15:47
  • 3
    Does this answer your question? [Getting command-line password input in Python](https://stackoverflow.com/questions/9202224/getting-command-line-password-input-in-python) – miquelvir Apr 07 '21 at 15:47

2 Answers2

6

There is no easy way to do this. However, you can use a couple of modules to create a similar function.

  1. PYAUTOGUI
import pyautogui

paswrd = pyautogui.password(text='', title='', default='', mask='*')

This opens a small window in which you can enter your password. Here, the password will be displayed as you want: it will use *s.

  1. GETPASS
import getpass

paswrd = getpass.getpass()

This will allow the user to enter a password normally, and the password won't show. It will be hidden. THIS ONLY WORKS IN THE TERMINAL, NOT SHELL

The Pilot Dude
  • 2,091
  • 2
  • 6
  • 24
2

You can use the getpass module to hide your password:

from getpass import getpass

password = getpass(prompt='Input your password: ') # the default prompt is 'Password: '

This won't replace it with * but at least you can't see the password.

Note: It will not work in the shell. Thanks to @PilotDude

Have a nice day
  • 1,007
  • 5
  • 11