Support multiple accounts
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 13s
All checks were successful
Build and Publish college-bot-v2 / build_and_publish (push) Successful in 13s
This commit is contained in:
parent
b8d5df6bbf
commit
41e2daa265
1 changed files with 10 additions and 2 deletions
|
@ -31,11 +31,19 @@ USERNAME = os.getenv("WEB_USERNAME", os.urandom(32).hex())
|
||||||
PASSWORD = os.getenv("WEB_PASSWORD", os.urandom(32).hex())
|
PASSWORD = os.getenv("WEB_PASSWORD", os.urandom(32).hex())
|
||||||
|
|
||||||
|
|
||||||
|
accounts = {
|
||||||
|
USERNAME: PASSWORD
|
||||||
|
}
|
||||||
|
if os.path.exists("./web-accounts.json"):
|
||||||
|
with open("./web-accounts.json") as f:
|
||||||
|
accounts.update(json.load(f))
|
||||||
|
|
||||||
|
|
||||||
def check_credentials(credentials: HTTPBasicCredentials = Depends(security)):
|
def check_credentials(credentials: HTTPBasicCredentials = Depends(security)):
|
||||||
err = HTTPException(status_code=401, detail="Unauthorized")
|
err = HTTPException(status_code=401, detail="Unauthorized")
|
||||||
if credentials.username != USERNAME:
|
if credentials.username not in accounts:
|
||||||
raise err
|
raise err
|
||||||
if not secrets.compare_digest(credentials.password, PASSWORD):
|
if not secrets.compare_digest(credentials.password, accounts[credentials.username]):
|
||||||
raise err
|
raise err
|
||||||
return credentials
|
return credentials
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue