Member Avatar for leegeorg07

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

Recommended Answers

All 11 Replies

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 for leegeorg07

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?

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

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 for leegeorg07

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?

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

#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 ]

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

commented: Grave digging and piggy backing = No no -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

You should try not to dig up old threads and append questions to them. Instead, create your own thread and ask your question.

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 for leegeorg07

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

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.