From 9581753e99668eed7b3df0daa549857b7c1dbf2a Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 22 Sep 2025 16:23:21 +0300 Subject: [PATCH] adds function to create salt for passwords. Salting process not yet implemented --- minimal_auth.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/minimal_auth.py b/minimal_auth.py index 5c317a6..04b11ce 100644 --- a/minimal_auth.py +++ b/minimal_auth.py @@ -2,6 +2,9 @@ import getpass # hides types characters, very useful import json import sys import hashlib +import random +import string + def get_credentials(): username = input('Enter your username: ') @@ -28,6 +31,19 @@ def write_pwdb(pwdb, pwdb_path): pwdb_file = open(pwdb_path, 'wt') json.dump(pwdb, pwdb_file) +def get_salt(char_num=10): + """Create random string of characters + + Parameters + ---------- + char_num: int. + Number of random characters to be created. + """ + + salt = ''.join(random.choices(string.ascii_uppercase + string.digits, k=char_num)) + + return salt + pwdb_path = 'pwdb.json' pwdb = read_pwdb(pwdb_path)