Tidying basic auth

main
bashrc 2026-04-27 19:35:36 +01:00
parent fa12fe6b15
commit bf3eb73b92
1 changed files with 13 additions and 14 deletions

27
auth.py
View File

@ -158,21 +158,20 @@ def authorize_basic(base_dir: str, path: str, auth_header: str,
print('DEBUG: passwords file missing') print('DEBUG: passwords file missing')
return False return False
provided_password = plain.split(':')[1] provided_password = plain.split(':')[1]
try: passwords_list = load_list(password_file,
with open(password_file, 'r', encoding='utf-8') as fp_pass: 'EX: failed to open password file')
for line in fp_pass: if passwords_list is None:
if not line.startswith(nickname + ':'):
continue
stored_password_base = line.split(':')[1]
stored_password = remove_eol(stored_password_base)
success = _verify_password(stored_password, provided_password)
if not success:
if debug:
print('DEBUG: Password check failed for ' + nickname)
return success
except OSError:
print('EX: failed to open password file')
return False return False
for login_str in passwords_list:
if not login_str.startswith(nickname + ':'):
continue
stored_password_base = login_str.split(':')[1]
stored_password = remove_eol(stored_password_base)
success = _verify_password(stored_password, provided_password)
if not success:
if debug:
print('DEBUG: Password check failed for ' + nickname)
return success
print('DEBUG: Did not find credentials for ' + nickname + print('DEBUG: Did not find credentials for ' + nickname +
' in ' + password_file) ' in ' + password_file)
return False return False