feat: 'password' auth method: support user addition

This commit is contained in:
Terry Geng
2020-05-23 14:46:21 +08:00
parent 19d868d352
commit e61f791c82
6 changed files with 152 additions and 77 deletions

14
util.py
View File

@ -386,6 +386,20 @@ def parse_file_size(human):
raise ValueError("Invalid file size given.")
def get_salted_password_hash(password):
salt = os.urandom(10)
hashed = hashlib.pbkdf2_hmac('sha1', password.encode("utf-8"), salt, 100000)
return hashed.hex(), salt.hex()
def verify_password(password, salted_hash, salt):
hashed = hashlib.pbkdf2_hmac('sha1', password.encode("utf-8"), bytearray.fromhex(salt), 100000)
if hashed.hex() == salted_hash:
return True
return False
class LoggerIOWrapper(io.TextIOWrapper):
def __init__(self, logger: logging.Logger, logging_level, fallback_io_buffer):
super().__init__(fallback_io_buffer, write_through=True)