From 1df93ff60c7a7ec87ff898939b3cd016c6416f3b Mon Sep 17 00:00:00 2001 From: malteheckelen Date: Mon, 20 Jan 2020 15:35:53 +0100 Subject: [PATCH] added salting function and a read function for an external list of salts --- auth.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/auth.py b/auth.py index 576f974..1ce83a7 100644 --- a/auth.py +++ b/auth.py @@ -7,11 +7,27 @@ def get_credentials(): password = getpass.getpass('Enter your password: ') return username, hash_string(password) +def salt_string(inputstring, salts, pwdb): + for salt in salts: + if ''.join(inputstring, salt) in pwdb.Values.ToList(): + continue + else: + salted_pw = ''.join(inputstring, salt) + salt_index = salts.index(salt) + return salted_pw, salt_index + def hash_string(inputstring): # hash the string hashed_password = sum(ord(char) for char in inputstring) - return hashed_password + return hashed_password + +def get_salts(filename): + # maybe reading it from an environment variable would be better + with open(filename, 'r') as f: + salts = f.read() + f.close() + def authenticate(username, password, pwdb): if username in pwdb: if password == pwdb[username]: