Can you make a simple "Enter password" program for me in Python please so I can study it?
I made one 3 months ago but then life stuff happened and got a new laptop now I am trying to teach myself python again and lost my self study files. Less than 10 lines please, I think mine was like 5 lines it was pretty straight forward using: If, input() and variables, else, print()
Also I want it to loop back to "Access Denied" every time password is wrong and when password is right I want it to say "Access Granted". There should be a pause at the end where it says "Please type anything/press enter to exit" after correct password is inputted.
Thank you in advance fellow humans :)
- 1 month agoFavourite answer
running = True
password = input('Enter a Password\n')
realpass = "12345"
if (password == realpass):
password = input('press enter to exit')
running = False
# little bit excessive with while loop but that's the best i can do
- husoskiLv 71 month ago
The normal input functions don't let you control echoing the password back. Python has a special module in the standard library that you should use to get a password in at the console.
import getpass # do this once at the top
pw = getpass.getpass() # get password with the default "Password: " prompt
pw = getpass.getpass("Tell me your secret: ") # get password with custom prompt
This won't work in IDLE under Windows and may not work properly in IDLE under Linux/Unix/MacOS. This is really for console or terminal windows only. (A GUI like Tkinter or wxPython will have different ways to enter passwords.)
- EddieJLv 71 month ago
while input ("Password: ")!="abc": print ("Access denied")
print ("Access granted")