main
Bob Mottram 2024-07-16 11:53:02 +01:00
parent 1ca9c4c303
commit 7b978570d2
1 changed files with 12 additions and 12 deletions

24
auth.py
View File

@ -151,8 +151,8 @@ def authorize_basic(base_dir: str, path: str, auth_header: str,
return False return False
provided_password = plain.split(':')[1] provided_password = plain.split(':')[1]
try: try:
with open(password_file, 'r', encoding='utf-8') as passfile: with open(password_file, 'r', encoding='utf-8') as fp_pass:
for line in passfile: for line in fp_pass:
if not line.startswith(nickname + ':'): if not line.startswith(nickname + ':'):
continue continue
stored_password_base = line.split(':')[1] stored_password_base = line.split(':')[1]
@ -188,10 +188,10 @@ def store_basic_credentials(base_dir: str,
if os.path.isfile(password_file): if os.path.isfile(password_file):
if text_in_file(nickname + ':', password_file): if text_in_file(nickname + ':', password_file):
try: try:
with open(password_file, 'r', encoding='utf-8') as fin: with open(password_file, 'r', encoding='utf-8') as fp_in:
with open(password_file + '.new', 'w+', with open(password_file + '.new', 'w+',
encoding='utf-8') as fout: encoding='utf-8') as fout:
for line in fin: for line in fp_in:
if not line.startswith(nickname + ':'): if not line.startswith(nickname + ':'):
fout.write(line) fout.write(line)
else: else:
@ -209,15 +209,15 @@ def store_basic_credentials(base_dir: str,
else: else:
# append to password file # append to password file
try: try:
with open(password_file, 'a+', encoding='utf-8') as passfile: with open(password_file, 'a+', encoding='utf-8') as fp_pass:
passfile.write(store_str + '\n') fp_pass.write(store_str + '\n')
except OSError: except OSError:
print('EX: unable to append password') print('EX: unable to append password')
return False return False
else: else:
try: try:
with open(password_file, 'w+', encoding='utf-8') as passfile: with open(password_file, 'w+', encoding='utf-8') as fp_pass:
passfile.write(store_str + '\n') fp_pass.write(store_str + '\n')
except OSError: except OSError:
print('EX: unable to create password file') print('EX: unable to create password file')
return False return False
@ -231,12 +231,12 @@ def remove_password(base_dir: str, nickname: str) -> None:
password_file = data_dir(base_dir) + '/passwords' password_file = data_dir(base_dir) + '/passwords'
if os.path.isfile(password_file): if os.path.isfile(password_file):
try: try:
with open(password_file, 'r', encoding='utf-8') as fin: with open(password_file, 'r', encoding='utf-8') as fp_in:
with open(password_file + '.new', 'w+', with open(password_file + '.new', 'w+',
encoding='utf-8') as fout: encoding='utf-8') as fp_out:
for line in fin: for line in fp_in:
if not line.startswith(nickname + ':'): if not line.startswith(nickname + ':'):
fout.write(line) fp_out.write(line)
except OSError as ex: except OSError as ex:
print('EX: unable to remove password from file ' + str(ex)) print('EX: unable to remove password from file ' + str(ex))
return return