How to declare a password (password) input?

Asked

Viewed 5,375 times

8

I wonder if there is a way to mask the input of characters in the input() python.

Ex:

Senha = 1234

Entrada = int(input("Digite sua senha: ")) 

In the entry above I wanted to change the letters entered by asterisks.

There are ways to do this in python?

  • Actually, using getpass does not change the letters inserted by asterisks. What it does is hide the digits of your password, which in my opinion is safer than displaying the asterisks, as you do not expose the amount of characters in your password. Example: import getpass password = getpass.getpass('Enter your password: ') print(password) > Enter your password: > 1234

  • In the programming you can write this manually and replace the data with the asterisk character.

1 answer

10


You can try using the "getpass".

import getpass
senha = getpass.getpass("Digite sua senha: ")

It will show asterisks when typing the password.

  • That’s right - the getpass is well crafted, and made for it (and comes along with Python).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.