So do you want something like this?
password = open('passwords.txt')
#each line in passwords.txt will have another passwords
password_list = password.readlines()
guess = raw_input("Enter the password: ")
if guess in password_list:
#print short story
else:
print "wrong password, program exiting"
raw_input()
#raw_input is there so the user can see the message
#before the program closes
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
Skill Endorsements: 1
Your problem is that readlines() attaches the newline character if present ...
password = open('passwords.txt')
username = open('usernames.txt')
#each line in passwords.txt will have another passwords
password_list = password.readlines()
username_list = username.readlines()
# for test print only ...
print password_list # notice the attached '\n' characters!!!!
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
print 'mary had a little lamb, her fleece as white as snow'
else:
print "wrong password, program exiting"
raw_input()
#raw_input is there so the user can see the message
#before the program closes
vegaseat
DaniWeb's Hypocrite
6,478 posts since Oct 2004
Reputation Points: 1,447
Solved Threads: 1,612
Skill Endorsements: 37
To add a user just open the username and password files in append mode (a) and then write a new username and password. Then they will be stored and available next time you run the program, or if you re-load the lists then straight away.
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
Skill Endorsements: 1
I think you can write user name with the next line containing password so that whenever the program searches for User name then it looks the next line for password. This will remove the need for password file. But then It will introduce the possibility of one password being equal to username. That can be avoided by appending password with special character which is ignored at the reading of the password. Let say real psswd is meal2000 then you store meal200#* and at retrieving from file you remove the *#
Just presenting Idea that you can use for your password
Stefano Mtangoo
Senior Poster
3,731 posts since Jun 2007
Reputation Points: 462
Solved Threads: 396
Skill Endorsements: 0
#each line in passwords.txt will have another passwords
password_list = password.readlines()
password_list = [ i.strip() for i in password_list ]
username_list = username.readlines()
username_list = [ i.strip() for i in username_list ]
jlm699
Veteran Poster
1,112 posts since Jul 2008
Reputation Points: 355
Solved Threads: 293
Skill Endorsements: 0
am looking for program that asks for a password and if that password is correct it will show a short story and if it is incorrect show not in assemply please help
You should try not to dig up old threads and append questions to them. Instead, create your own thread and ask your question.
scru
Posting Virtuoso
1,629 posts since Feb 2007
Reputation Points: 975
Solved Threads: 141
Skill Endorsements: 7
The simplest way is to use Python's built-in rot13 encoder. Write one program to give you the encoded password:
# program to rot13 encode a given password, here 'nixon'
# copy the result into your program that needs this password
# and then use encode('rot13') to match user password
password = 'nixon'
encoded_password = password.encode('rot13')
print(encoded_password) # avkba
Then use the encoded password in your main program, This way you don't give away the password in your code:
# program to use a rot13 encoded password, here 'avkba'
print('I will tell you a story if you enter the correct password')
# loop until the correct password has been entered
while True:
# for Python3 remove 'raw_'
pw = raw_input("Enter the password: ")
if pw.encode('rot13') == 'avkba':
print("Well, here is my story ...")
break
else:
print("password did not match, try again!")
sneekula
Nearly a Posting Maven
2,483 posts since Oct 2006
Reputation Points: 1,000
Solved Threads: 231
Skill Endorsements: 2