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

password program

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

8
Contributors
11
Replies
6 Months
Discussion Span
4 Years Ago
Last Updated
14
Views
leegeorg07
Posting Pro in Training
428 posts since Jul 2008
Reputation Points: 35
Solved Threads: 33
Skill Endorsements: 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
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
Skill Endorsements: 1

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?

leegeorg07
Posting Pro in Training
428 posts since Jul 2008
Reputation Points: 35
Solved Threads: 33
Skill Endorsements: 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
vegaseat
DaniWeb's Hypocrite
Moderator
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

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?

leegeorg07
Posting Pro in Training
428 posts since Jul 2008
Reputation Points: 35
Solved Threads: 33
Skill Endorsements: 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

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

swain
Newbie Poster
5 posts since May 2009
Reputation Points: 9
Solved Threads: 0
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

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

leegeorg07
Posting Pro in Training
428 posts since Jul 2008
Reputation Points: 35
Solved Threads: 33
Skill Endorsements: 0

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

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0922 seconds using 2.68MB