Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import json
|
3 |
import os
|
4 |
-
from cryptography.fernet import Fernet
|
5 |
|
6 |
# Initialize session state
|
7 |
if 'username' not in st.session_state:
|
@@ -41,18 +41,22 @@ def register_user(username, password):
|
|
41 |
|
42 |
def login_user(username, password):
|
43 |
if username in user_history:
|
44 |
-
encrypted_password = user_history[username]
|
45 |
try:
|
46 |
decrypted_password = fernet.decrypt(encrypted_password.encode()).decode()
|
47 |
if password == decrypted_password:
|
48 |
-
|
|
|
49 |
st.success("Logged in successfully!")
|
|
|
50 |
else:
|
51 |
st.error("Incorrect password. Please try again.")
|
52 |
except InvalidToken:
|
53 |
st.error("Invalid password. Please try again.")
|
54 |
else:
|
55 |
st.warning("Username not found. Please register first.")
|
|
|
|
|
56 |
|
57 |
def reset_password(username):
|
58 |
if username in user_history:
|
@@ -62,7 +66,7 @@ def reset_password(username):
|
|
62 |
else:
|
63 |
st.warning("Username not found.")
|
64 |
|
65 |
-
st.title("
|
66 |
|
67 |
if st.session_state.username:
|
68 |
st.subheader(f"Welcome back, {st.session_state.username}!")
|
@@ -77,7 +81,8 @@ else:
|
|
77 |
col1, col2 = st.columns(2)
|
78 |
with col1:
|
79 |
if st.button("π Login"):
|
80 |
-
login_user(username, password)
|
|
|
81 |
with col2:
|
82 |
if st.button("π Register"):
|
83 |
register_user(username, password)
|
|
|
1 |
import streamlit as st
|
2 |
import json
|
3 |
import os
|
4 |
+
from cryptography.fernet import Fernet, InvalidToken
|
5 |
|
6 |
# Initialize session state
|
7 |
if 'username' not in st.session_state:
|
|
|
41 |
|
42 |
def login_user(username, password):
|
43 |
if username in user_history:
|
44 |
+
encrypted_password = user_history[username]['password']
|
45 |
try:
|
46 |
decrypted_password = fernet.decrypt(encrypted_password.encode()).decode()
|
47 |
if password == decrypted_password:
|
48 |
+
st.session_state.username = username
|
49 |
+
st.session_state.scratch_pad = user_history[username]['scratch_pad']
|
50 |
st.success("Logged in successfully!")
|
51 |
+
return True
|
52 |
else:
|
53 |
st.error("Incorrect password. Please try again.")
|
54 |
except InvalidToken:
|
55 |
st.error("Invalid password. Please try again.")
|
56 |
else:
|
57 |
st.warning("Username not found. Please register first.")
|
58 |
+
return False
|
59 |
+
|
60 |
|
61 |
def reset_password(username):
|
62 |
if username in user_history:
|
|
|
66 |
else:
|
67 |
st.warning("Username not found.")
|
68 |
|
69 |
+
st.title("Memory of Me - State Aware Authentication and User Data Memory")
|
70 |
|
71 |
if st.session_state.username:
|
72 |
st.subheader(f"Welcome back, {st.session_state.username}!")
|
|
|
81 |
col1, col2 = st.columns(2)
|
82 |
with col1:
|
83 |
if st.button("π Login"):
|
84 |
+
if login_user(username, password):
|
85 |
+
st.experimental_rerun()
|
86 |
with col2:
|
87 |
if st.button("π Register"):
|
88 |
register_user(username, password)
|