We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,267 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Password Protection Program

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!

4
Contributors
5
Replies
1 Day
Discussion Span
1 Year Ago
Last Updated
6
Views
The Bl
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

pyTony
pyMod
Moderator
6,310 posts since Apr 2010
Reputation Points: 879
Solved Threads: 987
Skill Endorsements: 26

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

pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
Skill Endorsements: 0

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)
pyguy62
Posting Whiz
353 posts since Aug 2011
Reputation Points: 34
Solved Threads: 19
Skill Endorsements: 0

Note, since raw_input echos what's typed to stdout, you may want to use the getpass moudle - http://docs.python.org/library/getpass.html

Enalicho
Junior Poster in Training
62 posts since Aug 2011
Reputation Points: 28
Solved Threads: 13
Skill Endorsements: 0

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

pyTony
pyMod
Moderator
6,310 posts since Apr 2010
Reputation Points: 879
Solved Threads: 987
Skill Endorsements: 26

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0716 seconds using 2.71MB