Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hashlib
- import os
- from getpass import getpass
- from pathlib import Path
- escapes = ''.join([chr(char) for char in range(7, 14)])
- lOrS = input("Login or signup: ").lower()
- while (lOrS != "login" and lOrS != "signup"):
- lOrS = input("Error. Login or signup: ").lower()
- if(lOrS == "signup"):
- userS = input("Username: ")
- while (Path((hashlib.sha512(userS.encode()).hexdigest())).is_dir()):
- userS = input("Error Username taken. Username: ")
- print("Password will not be displayed")
- pwRS = getpass("Enter password: ")
- pwC = getpass("Retype password: ")
- while (pwRS != pwC):
- pwRS = getpass("Enter password: ")
- pwC = getpass("Retype password: ")
- salt = os.urandom(64)
- pwRS = pwRS.encode() + salt
- pwS = hashlib.sha512(pwRS).hexdigest()
- folder = hashlib.sha512(userS.encode()).hexdigest()
- os.makedirs(folder)
- uH = open(folder + '/hash.txt', 'a+')
- uH.write(pwS)
- uH.close()
- uS = open(folder + '/salt.txt', 'ab+')
- uS.write(salt)
- uS.close()
- else:
- def login():
- u = input("Enter Username: ")
- p = getpass("Enter Password: ")
- if(os.path.exists(hashlib.sha512(u.encode()).hexdigest())):
- filepath = hashlib.sha512(u.encode()).hexdigest()
- uHP = open(filepath + '/hash.txt', 'r')
- uSP = open(filepath + '/salt.txt', 'rb')
- uHash = uHP.readline()
- uSalt = uSP.read()
- checkhash = p.encode() + uSalt
- if(hashlib.sha512(checkhash).hexdigest() == uHash):
- print('logged in')
- else:
- print("incorrect username or password")
- login()
- else:
- print("incorrect username or password")
- login()
- uSP.close()
- uHP.close()
- login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement