I have been trying to create a program that asks for a username and password, and if the user gets it right exits the program, if they get it wrong asks again, and if they get it wrong again logs out of the system.

TWO QUESTIONS:
1: is this possible?
2: if it is, can anyone give me an idea on how to do this?

I have this so far: (i think it might work, but note that so far i haven't included the part where it logs out; i obviously don't know how, or if it is possible).

p = open("C:/Users/HoulahanB/Password.txt")
u = open("C:/Users/HoulahanB/Username.txt")

password_list = Password.readline()
username_list = Username.readline()

print password_list
print username_list

guessuser = raw_input("Enter the username: ")
guesspass = raw_input("Enter the password: ")
if guessuser in username_list:
    if guesspass in password_list:
        print "thank you for logging in", guessuser
else:
    print "wrong password, program exiting"
    raw_input()
exit()

PLS HELP!

Nobody seems to be in hurry. Normally you continue after password match and otherwise exit. Your code is joke as you would have error latest at line 4. I do not understand also how you would check passwords from everybody and accept them to all users.

If you want it to continue, regardless of under what circumstance, you need to create a loop.

here's a hint:

users={'op':'doesntusegoogle',
        'daniweb':'toohelpful'}

username=raw_input('Username: ')
while username not in users.keys():
    print('\nInvalid username. Please try again\n')
    username=raw_input('Username: ')

password=raw_input('Password: ')
while password!=users[username]:
    print('\nInvalid password. Please try again\n')
    password=raw_input('Password: ')
print('Welcome,'username)

I would prefer to use withdrawn tkinter password entry window, even from console app.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.