ykl7 commited on
Commit
1974e91
·
1 Parent(s): ee3fca4

simplify auth to remove bcrypt

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -3,6 +3,7 @@ import random
3
  import time
4
  import hmac
5
  import bcrypt
 
6
 
7
  st.header(" Scientific Claim Verification ")
8
 
@@ -18,20 +19,27 @@ def check_password():
18
 
19
  def password_entered():
20
  """Checks whether a password entered by the user is correct."""
21
-
22
- if st.session_state["username"] in st.secrets["passwords"]:
23
- stored_hashed_password = st.secrets["passwords"][st.session_state["username"]] # Retrieved as a string
24
-
25
- # Convert hashed password back to bytes if it's stored as a string
26
- if isinstance(stored_hashed_password, str):
27
- stored_hashed_password = stored_hashed_password.encode()
28
 
29
- # Compare user-entered password (encoded) with stored hash
30
- if bcrypt.checkpw(st.session_state["password"].encode(), stored_hashed_password):
31
- st.session_state["password_correct"] = True
32
  del st.session_state["password"] # Remove credentials from session
33
  del st.session_state["username"]
34
  return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  # If authentication fails
37
  st.session_state["password_correct"] = False
 
3
  import time
4
  import hmac
5
  import bcrypt
6
+ import os
7
 
8
  st.header(" Scientific Claim Verification ")
9
 
 
19
 
20
  def password_entered():
21
  """Checks whether a password entered by the user is correct."""
 
 
 
 
 
 
 
22
 
23
+ stored_password = os.getenv(st.session_state["username"])
24
+ if stored_password == st.session_state["password"]:
25
+ st.session_state["password_correct"] = True
26
  del st.session_state["password"] # Remove credentials from session
27
  del st.session_state["username"]
28
  return
29
+
30
+ # if st.session_state["username"] in st.secrets["passwords"]:
31
+ # stored_hashed_password = st.secrets["passwords"][st.session_state["username"]] # Retrieved as a string
32
+
33
+ # # Convert hashed password back to bytes if it's stored as a string
34
+ # if isinstance(stored_hashed_password, str):
35
+ # stored_hashed_password = stored_hashed_password.encode()
36
+
37
+ # # Compare user-entered password (encoded) with stored hash
38
+ # if bcrypt.checkpw(st.session_state["password"].encode(), stored_hashed_password):
39
+ # st.session_state["password_correct"] = True
40
+ # del st.session_state["password"] # Remove credentials from session
41
+ # del st.session_state["username"]
42
+ # return
43
 
44
  # If authentication fails
45
  st.session_state["password_correct"] = False