How to hide password characters in Python

Home / Uncategorized / How to hide password characters in Python

Question:
I am new in the world of python. I created a simple program in which I added username and password entry ( no GUI) by using "if else" conditional expression. When i write username in program it appear as simple text but it’s ok but when I write password it also appear as simple text. I want to write password in the form of ‘*’ like all login prompts. password => ***** ?????????.
usr = (str(input(‘USERNAME : ‘)))
if usr == ‘python’:password = (str(input(‘PASSWORD : ‘)))
if password == ‘root’:print (‘login succesfull’)
else:print (‘wrong password’)
else:print (‘wrong username’)


Answer:
There is getpass(), a function which hides the user input.
Import getpass

password = getpass.getpass()
print(password)

mypass = getpass.getpass("PASSWORD : ")
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *