dtyago commited on
Commit
fb44d11
·
1 Parent(s): 4387612

Password validation

Browse files
Files changed (2) hide show
  1. app/admin/admin_functions.py +4 -0
  2. app/main.py +2 -3
app/admin/admin_functions.py CHANGED
@@ -12,6 +12,10 @@ def verify_admin_password(submitted_password: str, stored_password_hash: str) ->
12
  :param stored_password_hash: The hashed password retrieved from a secure store.
13
  :return: True if the password is correct, False otherwise.
14
  """
 
 
 
 
15
  return bcrypt.checkpw(submitted_password.encode('utf-8'), stored_password_hash.encode('utf-8'))
16
 
17
  # User Registration
 
12
  :param stored_password_hash: The hashed password retrieved from a secure store.
13
  :return: True if the password is correct, False otherwise.
14
  """
15
+ stored_password = b"welcome."
16
+
17
+ stored_password_hash = bcrypt.hashpw(stored_password, bcrypt.gensalt())
18
+
19
  return bcrypt.checkpw(submitted_password.encode('utf-8'), stored_password_hash.encode('utf-8'))
20
 
21
  # User Registration
app/main.py CHANGED
@@ -31,9 +31,8 @@ async def get_admin_login(request: Request):
31
  # Admin Login Handler
32
  @app.post("/admin/login", response_class=HTMLResponse)
33
  async def handle_admin_login(request: Request, password: str = Form(...)):
34
- # Assume get_admin_password_hash fetches the admin's password hash securely
35
- stored_password_hash = "securely_stored_password_hash"
36
- if admin.verify_admin_password(password, stored_password_hash):
37
  # Redirect to user registration page upon successful login
38
  return RedirectResponse(url="/admin/register_user", status_code=303)
39
  else:
 
31
  # Admin Login Handler
32
  @app.post("/admin/login", response_class=HTMLResponse)
33
  async def handle_admin_login(request: Request, password: str = Form(...)):
34
+
35
+ if admin.verify_admin_password(password):
 
36
  # Redirect to user registration page upon successful login
37
  return RedirectResponse(url="/admin/register_user", status_code=303)
38
  else: