1,105,395 Community Members

password program

Member Avatar
leegeorg07
Posting Pro in Training
428 posts since Jul 2008
Reputation Points: 23 [?]
Q&As Helped to Solve: 33 [?]
Skill Endorsements: 0 [?]
 
0
 

hi again im looking to make a program that asks for a password and if that password is correct it will show a short story and if it is incorrect it will show so and then close.
i want to include a backdoor code for my use and later on i want to edit this code to make password protected program.
if possible i also want the passwords to be stored in a file.

thanks for any help

leegeorg07

Member Avatar
Paul Thompson
Veteran Poster
1,095 posts since May 2008
Reputation Points: 178 [?]
Q&As Helped to Solve: 189 [?]
Skill Endorsements: 3 [?]
 
0
 

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
Member Avatar
leegeorg07
Posting Pro in Training
428 posts since Jul 2008
Reputation Points: 23 [?]
Q&As Helped to Solve: 33 [?]
Skill Endorsements: 0 [?]
 
0
 

yes sort of but ive edited it to this

password = open('passwords.txt')
username = open('usernames.txt')
#each line in passwords.txt will have another passwords
password_list = password.readlines()
username_list = username.readline()
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

but when i enter the correct username and password

'leegeorg07' and 'bob23456'

it does not show the short story
also i want the program to be able to add new users can you help me?

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 

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
Member Avatar
Paul Thompson
Veteran Poster
1,095 posts since May 2008
Reputation Points: 178 [?]
Q&As Helped to Solve: 189 [?]
Skill Endorsements: 3 [?]
 
0
 

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.

Member Avatar
leegeorg07
Posting Pro in Training
428 posts since Jul 2008
Reputation Points: 23 [?]
Q&As Helped to Solve: 33 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks for the post vedaseat, can you tell me how to fix it? also i tried just adding a new password and username, it works but all usernames and passwords work for eachother how can i fix this?

Member Avatar
Stefano Mtangoo
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 441 [?]
Q&As Helped to Solve: 394 [?]
Skill Endorsements: 2 [?]
 
0
 

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

Member Avatar
jlm699
Veteran Poster
1,104 posts since Jul 2008
Reputation Points: 320 [?]
Q&As Helped to Solve: 295 [?]
Skill Endorsements: 0 [?]
 
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 ]
Member Avatar
swain
Newbie Poster
5 posts since May 2009
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

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

Member Avatar
scru
Posting Virtuoso
1,624 posts since Feb 2007
Reputation Points: 909 [?]
Q&As Helped to Solve: 165 [?]
Skill Endorsements: 16 [?]
Featured
 
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.

Member Avatar
sneekula
Nearly a Posting Maven
2,496 posts since Oct 2006
Reputation Points: 917 [?]
Q&As Helped to Solve: 263 [?]
Skill Endorsements: 5 [?]
 
0
 

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!")
Member Avatar
leegeorg07
Posting Pro in Training
428 posts since Jul 2008
Reputation Points: 23 [?]
Q&As Helped to Solve: 33 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks, i just thought, why dont i use a dictionary of passwords and usernames?, thanks sneekula i might add in some sort of encryption into the password and/or username

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article