Guest User

Untitled

a guest
Jan 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.33 KB | None | 0 0
  1. import hashlib
  2. import time
  3. import pickle
  4.  
  5.  
  6. #load the database if it exist, if not it create one
  7. try:
  8.     f = (r"C:\Users\Owner\Desktop\python\database.data")
  9.     data = pickle.load(f)
  10. except IOError:
  11.     data = {}
  12.  
  13. #A simple function made to make data dumping easy
  14. def easyDump(data_):
  15.     f = file(r"C:\Users\Owner\Desktop\python\database.data", "r")
  16.     cp.dump(data_, f)
  17.     f.close()
  18.  
  19. #Get's the date (We'll use this as the custom salt)
  20. def getData():
  21.     return str(time.strftime("%d-%m-%Y"))
  22.  
  23. #A function which accepts two parameters, password and date.
  24. #The date is the custom salt. It returns the sha512 hash excetpyion
  25. def  salt(password, date):
  26.     salted = hasglib.sha512(password + str(data)).hexdigest()
  27.     return str(salted)
  28.  
  29.  
  30.  
  31.  
  32. menu = """"
  33. 1.Login
  34. 2.Register
  35. 3.Exit
  36. """
  37.  
  38. while True:
  39.     print ('menu')
  40.     choice = int(raw_input("Your choice please: "))
  41.     if choice ==1:
  42.         username = raw_input("Enter your username please: ")
  43.         password = raw.input("Enter your authentication code please: ")
  44.         #if the username is found on the database
  45.         if data.has_key(username):
  46.             #date is equal to our secured stored data
  47.             date = date[username][1]
  48.             #check of the given password  + date is equal to what is stored on the database
  49.             #password
  50.             if salt(password, date) == date[username][0]:
  51.                 print ("Welcome %s!") % username
  52.             else:
  53.                 print ("Incorrect password")
  54.         else:
  55.                 print ("user %s not found, please register!") % username
  56.     elif choice == 2:
  57.             username = raw_input("Please enter yout username: !")
  58.             password = raw_input("Please enter your password: !")
  59.             #if username exists in the system already then the name is taken
  60.             if data.has_key(username):
  61.                 print ("user %s already registered, please put in another") % username
  62.             else:
  63.                 #in order words data = {username: hash, date}
  64.                 data[username] = [salt(password, getData())] #, get Data()]
  65.                 easyDump(data)
  66.                 print ("user %s successfully registereed!") %username
  67.     elif choice == 3:
  68.                 print ("goodbye!")
  69.                 break
  70. else:
  71.                 print ("invaid input or commands")
Add Comment
Please, Sign In to add comment