Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from base64 import *
- #=-=-=-=-=-=-=-=-=-=-=-=-#
- # #
- # Login System #
- # #
- #=-=-=-=-=-=-=-=-=-=-=-=-#
- #Define the list of account to allow in:
- def txt_to_dict():
- """The purpose of this function is to take
- the information found in the account_info.txt
- file and save it to a dictionary proper."""
- user_info = open("account_info.txt", "r")
- raw_info = []
- account_info = {}
- #Store the information into an array
- for each in user_info:
- temp = each.rstrip('\n')
- raw_info.append(temp)
- user_info.close()
- #Take each chunk of text and seperate it proper
- for each in raw_info:
- count = 0
- if each[0] != " ":
- while each[count] != ";":
- count += 1dt
- if each[count] == ";":
- username = each[0:count]
- password = each[(count+1):len(each)]
- account_info[username] = password
- #return raw_info
- login(account_info)
- def update_txt(account_list, username, password):
- user_info = open("account_info.txt", "a")
- user_info.write(username + ";" + password + "\n")
- user_info.close()
- create_txt(username)
- def string_encode(string):
- #Take the user string and encode it once:
- stringEnc1 = ""
- stringEnc1 = b64encode(string)
- #Then encode it again:
- stringEnc2 = ""
- stringEnc2 = b64encode(stringEnc1)
- return stringEnc2
- def string_decode(string):
- #Take the inputted string and decode it twice:
- stringDec1 = ""
- stringDec1 = b64decode(string)
- stringDec2 = ""
- stringDec2 = b64decode(stringDec1)
- return stringDec2
- def login(account_list):
- print account_list
- """This function takes the user's login
- information encrypt it using the string_encode
- function. Then it runs the information through
- a dictionary of account information."""
- #Get the user provided information (encrypting the password when receiving)
- account_username = raw_input(">>> ")
- account_password = string_encode(raw_input(">>> "))
- #Make sure the username is lowercase:
- account_username = account_username.lower()
- account_username = string_encode(account_username)
- #Set up a local boolean to determine if the login
- #was successful or not
- login_success = False
- #Determine if the user wants to register with this
- #local variable:
- register = ""
- #Then run it through the dictionary of usernames
- #Loop the dictionary's first key to check for the
- #correct username, then do it again for the password:
- for username in account_list:
- if account_username == username:
- if account_password == account_list[username]:
- print "Login successful"
- login_success = True
- data_menu(username)
- #If the login failed but the username is in the list,
- #tell the user the password is incorrect.
- if login_success == False and account_username in account_list:
- print "Sorry, password incorrect."
- if login_success == False and account_username not in account_list:
- print "Sorry, username not recognized."
- register = raw_input("Do you wish to register your information? y/n \n>>> ")
- if register.lower() == "y":
- account_register(account_list)
- def account_register(account_list):
- #Clientside
- """This function serves to take the user's
- login information and append it to the account
- list so he/she can sign in."""
- #Get the info to add
- user_to_add = raw_input("Username to add \n>>> ").lower()
- user_to_add = string_encode(user_to_add)
- pass_to_add = string_encode(raw_input("Password to add \n>>> "))
- pass_to_add2 = string_encode(raw_input("Retype password \n>>> "))
- #Double check (again) to make sure the username to add is NOT in the system:
- if user_to_add in account_list:
- print "woah there! That username is already registered."
- #Make sure the two passwords match eachother!
- if pass_to_add == pass_to_add2:
- print "Saved succesfully!"
- update_txt(account_list, user_to_add, pass_to_add)
- else:
- print "The two passwords do not match."
- login(account_list)
- #Then return to the login screen
- login(account_list)
Advertisement
Add Comment
Please, Sign In to add comment