Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib
- import time
- #cPickle is faster then pickle but not available in all python releases
- #thats why i used a try/accept there
- try: import cPickle as cp
- #load the database if it exist, if not it create one
- try:
- f =(r"C:\Users\Owner\Desktop\python\database.data")
- data = cp.load(f)
- except IOError:
- data = {}
- #A simple function made to make data dumping easy
- def easyDump(data_):
- f = file(r"C:\Users\Owner\Desktop\python\database.data", "w")
- cp.dump(data_, f)
- f.close()
- #Get's the date (We'll use this as the custom salt)
- def getData():
- return str(time.strftime("%d-%m-%Y"))
- #A function which accepts two parameters, password and date.
- #The date is the custom salt. It returns the sha512 hash excetpyion
- def salt(password, date):
- salted = hasglib.sha512(password + str(data)).hexdigest()
- retun str(salted)
- menu = """"
- 1.Login
- 2.Register
- 3.Exit
- """
- while True:
- print menu
- choice = int(raw_input("Your choice please: "))
- if choice ==1:
- username = raw_input("Enter your username please: ")
- password = raw.input("Enter your authentication code please: ")
- #if the username is found on the database
- if data.has_key(username):
- #date is equal to our secured stored data
- date = date[username][1]
- #check of the given password + date is equal to what is stored on the database
- #password
- if salt(password, date) == date[username][0]:
- print"Welcome %s!" % username
- else:
- print "Incorrect password"
- else:
- print "user %s not found, please register!" % username
- elif choice == 2:
- username = raw_input("Please enter yout username: !")
- password = raw_input("Please enter your password: !")
- #if username exists in the system already then the name is taken
- if data.has_key(username):
- print "user %s already registered, please put in another % username
- else:
- #in order words data = {username: hash, date}
- data[username] = [salt(password, getData()), get Data()]
- easyDump(data)
- print "user %s successfully registereed!" %username
- elif choice == 3:
- print "goodbye!"
- break
- else:
- print "invaid input or commands"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement