1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Rep Power

    TXT File reading

    Hi, i'm relatively new to python programming and have been asked to do a project for university. I'm attempting to make a user account program with a register, login and lost password function.

    I've decided to go down the route of when a user register their account, the vars to temporarily store the username, email & pw are then added to a dictionary. The dictionaries at the end of the registration then are saved to a external txt file.

    I have reached my first problem in that I don't know how to read from the text files and create an if statement to check whether an email exists for example.

    The code so far:

    option = True
    register = True

    userdict = {}
    pwddict = {}
    emaildict = {}

    f = open('db.txt', 'a')

    while (option):
    print("""Choose from one of the following options...
    1) Register
    2) Login
    3) Lost Password""")
    option = input("")
    if option == '1' or option == 'register':
    print("You have chosen to register")
    option = False
    elif option == '2' or option == 'login':
    print("You have chosen to login")
    option = False
    elif option == '3' or option == 'lost password':
    print("You have chosen the lost password function")
    option = False

    print("We will need a username, your email and a password.")
    username = input(str("Type your desired username: "))
    email = input(str("Type your email address: "))
    password = input(str("Type your password: "))

    emaildict [username] = email
    pwddict [username] = password
    print("Your details have been saved, you will receive email confirming containing your details shortly.")
    Any help is appreciated!
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    I'm sure your question is interesting and important.

    You should use the pickle or shelve module. These are documented here. python 2

    or python3 here
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo