dtyago commited on
Commit
843bda3
1 Parent(s): 10f29f7

Externalize admin password

Browse files
Dockerfile CHANGED
@@ -7,7 +7,8 @@ RUN useradd -m -u 1000 user
7
  # Set environment variables for the non-root user
8
  ENV HOME=/home/user \
9
  PATH=/home/user/.local/bin:$PATH \
10
- NAME=EduConnect
 
11
 
12
  # Set the non-root user's home directory as the working directory
13
  WORKDIR $HOME
 
7
  # Set environment variables for the non-root user
8
  ENV HOME=/home/user \
9
  PATH=/home/user/.local/bin:$PATH \
10
+ NAME=EduConnect \
11
+ EC_ADMIN_PWD='$2b$12$zybxm7XMoGCVV3ovNDcXt.r2QJUhtj7miYfEfuBw9UGqViTIRFg72'
12
 
13
  # Set the non-root user's home directory as the working directory
14
  WORKDIR $HOME
app/admin/admin_functions.py CHANGED
@@ -1,24 +1,26 @@
1
  from fastapi import HTTPException, UploadFile, File, Form
2
  from typing import Optional
3
  import bcrypt
4
-
5
 
6
  # Admin Authentication
7
  def verify_admin_password(submitted_user: str, submitted_password: str) -> bool:
8
  """
9
  Verifies the submitted password against the stored hash.
10
-
 
11
  :param submitted_password: The password submitted by the user.
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" "
16
  if submitted_user == "admin":
17
- stored_password = b"welcome." # Later retrieve from secrets
18
-
19
- stored_password_hash = bcrypt.hashpw(stored_password, bcrypt.gensalt())
 
 
 
 
20
 
21
- return bcrypt.checkpw(submitted_password.encode('utf-8'), stored_password_hash.encode('utf-8'))
22
 
23
  # User Registration
24
  async def register_user(email: str, name: str, role: str, file: UploadFile = File(...)) -> Optional[str]:
 
1
  from fastapi import HTTPException, UploadFile, File, Form
2
  from typing import Optional
3
  import bcrypt
4
+ import os
5
 
6
  # Admin Authentication
7
  def verify_admin_password(submitted_user: str, submitted_password: str) -> bool:
8
  """
9
  Verifies the submitted password against the stored hash.
10
+
11
+ :param submitted_user: The username submitted by the user.
12
  :param submitted_password: The password submitted by the user.
 
13
  :return: True if the password is correct, False otherwise.
14
  """
 
15
  if submitted_user == "admin":
16
+ # Retrieve the stored hash from environment variable
17
+ stored_password_hash = os.getenv("EC_ADMIN_PWD", "").encode('utf-8')
18
+
19
+ # Directly compare the submitted password with the stored hash
20
+ return bcrypt.checkpw(submitted_password.encode('utf-8'), stored_password_hash)
21
+
22
+ return False
23
 
 
24
 
25
  # User Registration
26
  async def register_user(email: str, name: str, role: str, file: UploadFile = File(...)) -> Optional[str]:
app/admin/templates/admin_login.html CHANGED
@@ -2,7 +2,7 @@
2
  <head>
3
  <title>EduConnect Administration- login page</title>
4
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
- <link href="static/bootstrap.min.css" rel="stylesheet" media="screen">
6
  </head>
7
  <body>
8
  <div class="container">
 
2
  <head>
3
  <title>EduConnect Administration- login page</title>
4
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
+ <link href="static/css/mvp.css" rel="stylesheet" media="screen">
6
  </head>
7
  <body>
8
  <div class="container">
app/admin/templates/user_registration.html CHANGED
@@ -2,6 +2,8 @@
2
  <html>
3
  <head>
4
  <title>User Registration</title>
 
 
5
  </head>
6
  <body>
7
  <h2>User Registration</h2>
 
2
  <html>
3
  <head>
4
  <title>User Registration</title>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <link href="static/css/mvp.css" rel="stylesheet" media="screen">
7
  </head>
8
  <body>
9
  <h2>User Registration</h2>
requirements.txt CHANGED
@@ -10,4 +10,5 @@ python-multipart==0.0.5 # Necessary for form data handling, including fil
10
  numpy # Fundamental package for scientific computing.
11
  chromadb==0.4.22 # Vector database interaction libraries.
12
  keras-facenet==0.3.2 # For face recognition and embedding, used alongside MTCNN.
13
- jinja2==3.0.* # For Admin site redndering
 
 
10
  numpy # Fundamental package for scientific computing.
11
  chromadb==0.4.22 # Vector database interaction libraries.
12
  keras-facenet==0.3.2 # For face recognition and embedding, used alongside MTCNN.
13
+ jinja2==3.0.* # For Admin site redndering
14
+ bcrypt==4.1.* # For hashing secrets