louiecerv commited on
Commit
5f097cc
·
1 Parent(s): ef7778e

first full sync with remote

Browse files
__pycache__/app.cpython-313.pyc ADDED
Binary file (8.79 kB). View file
 
__pycache__/utils.cpython-313.pyc ADDED
Binary file (644 Bytes). View file
 
app.py ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import sqlite3
3
+ from passlib.hash import bcrypt
4
+ import pandas as pd
5
+ import re
6
+ import warnings
7
+ warnings.filterwarnings("ignore", message="module 'bcrypt' has no attribute '__about__'")
8
+ if "is_starting" not in st.session_state:
9
+ st.session_state["is_starting"] = True
10
+
11
+ if "authenticated" not in st.session_state:
12
+ st.session_state["authenticated"] = False
13
+
14
+ from pages.About import show_about
15
+ from pages.Text_prompt import show_text_prompt
16
+ from pages.Multimodal import show_multimodal
17
+ from pages.Settings import show_settings
18
+
19
+
20
+ if "authenticated" not in st.session_state:
21
+ st.session_state["authenticated"] = False
22
+
23
+ # --- Database functions ---
24
+ def create_usertable():
25
+ conn = sqlite3.connect('users.db')
26
+ c = conn.cursor()
27
+ c.execute('CREATE TABLE IF NOT EXISTS userstable(username TEXT, password TEXT)')
28
+ conn.commit()
29
+ conn.close()
30
+
31
+ def add_userdata(username, password):
32
+ conn = sqlite3.connect('users.db')
33
+ c = conn.cursor()
34
+ c.execute('INSERT INTO userstable(username, password) VALUES (?,?)', (username, password))
35
+ conn.commit()
36
+ conn.close()
37
+
38
+ def login_user(username, password):
39
+ conn = sqlite3.connect('users.db')
40
+ c = conn.cursor()
41
+ c.execute('SELECT password FROM userstable WHERE username =?', (username,))
42
+ stored_hash = c.fetchone()
43
+ conn.close()
44
+
45
+ if stored_hash:
46
+ stored_hash = stored_hash[0]
47
+ return check_hashes(password, stored_hash)
48
+ else:
49
+ return False
50
+
51
+ def view_all_users():
52
+ conn = sqlite3.connect('users.db')
53
+ c = conn.cursor()
54
+ c.execute('SELECT * FROM userstable')
55
+ data = c.fetchall()
56
+ conn.close()
57
+ return data
58
+
59
+ # --- Hashing ---
60
+ def make_hashes(password):
61
+ return bcrypt.hash(password)
62
+
63
+ def check_hashes(password, hashed_text):
64
+ return bcrypt.verify(password, hashed_text)
65
+
66
+ # --- Authentication ---
67
+ def authenticate(username, password):
68
+ return login_user(username, password)
69
+
70
+ def logout():
71
+ del st.session_state["authenticated"]
72
+ del st.session_state["username"]
73
+ del st.session_state["page"]
74
+
75
+ # --- Initialize session state ---
76
+ if "authenticated" not in st.session_state:
77
+ st.session_state["authenticated"] = False
78
+ if "username" not in st.session_state:
79
+ st.session_state["username"] = None
80
+ if "page" not in st.session_state:
81
+ st.session_state["page"] = "login"
82
+
83
+ # --- Login page ---
84
+ def login_page():
85
+ st.title("User Authentication System")
86
+ st.subheader("Login Section")
87
+ username = st.text_input("User Name")
88
+ password = st.text_input("Password", type='password')
89
+ if st.button("Login"):
90
+ result = authenticate(username.lower(), password)
91
+ if result:
92
+ st.session_state["authenticated"] = True
93
+ st.session_state["username"] = username
94
+ st.success("Logged In as {}".format(username))
95
+ st.session_state["page"] = "main"
96
+ st.session_state["is_starting"] = False
97
+ st.rerun()
98
+ else:
99
+ st.warning("Incorrect Username/Password")
100
+
101
+ st.write("Don't have an account? Click Signup.")
102
+ # --- Signup button ---
103
+ if st.button("Signup"):
104
+ st.session_state["page"] = "signup"
105
+ st.rerun()
106
+
107
+ # --- Signup page ---
108
+ def signup_page():
109
+ st.subheader("Create New Account")
110
+ new_user = st.text_input("Username")
111
+ new_password = st.text_input("Password", type='password')
112
+
113
+ # Display password requirements
114
+ st.write("Password Requirements:")
115
+ st.write("* Minimum length: 8 characters")
116
+ st.write("* Mix of uppercase and lowercase letters")
117
+ st.write("* At least one number")
118
+ st.write("* At least one special character")
119
+
120
+ # Validate password strength
121
+ if st.button("Signup"):
122
+ password_strength = validate_password(new_password)
123
+ if password_strength:
124
+ hashed_new_password = make_hashes(new_password)
125
+ add_userdata(new_user, hashed_new_password)
126
+ st.success("You have successfully created a valid Account")
127
+ st.info("Go to Login Menu to login")
128
+ st.session_state["page"] = "login"
129
+ st.rerun()
130
+ else:
131
+ st.error("Password does not meet the requirements.")
132
+
133
+ # --- Validate password strength ---
134
+ def validate_password(password):
135
+ # Define password requirements
136
+ min_length = 8
137
+ has_uppercase = re.search(r"[A-Z]", password)
138
+ has_lowercase = re.search(r"[a-z]", password)
139
+ has_number = re.search(r"\d", password)
140
+ has_symbol = re.search(r"[!@#$%^&*()_+=-{};:'<>,./?]", password)
141
+
142
+ # Check if password meets all requirements
143
+ if (len(password) >= min_length and
144
+ has_uppercase and
145
+ has_lowercase and
146
+ has_number and
147
+ has_symbol):
148
+ return True
149
+ else:
150
+ return False
151
+
152
+ # --- Manage users page ---
153
+ def manage_users_page():
154
+ st.subheader("User Management")
155
+ user_result = view_all_users()
156
+ clean_db = pd.DataFrame(user_result, columns=["Username", "Password"])
157
+ st.dataframe(clean_db)
158
+
159
+ # --- Main app ---
160
+ def main():
161
+ create_usertable()
162
+
163
+ if st.session_state["page"] == "login":
164
+ login_page()
165
+ elif st.session_state["page"] == "signup":
166
+ signup_page()
167
+ else:
168
+
169
+ st.title("Welcome")
170
+ st.write("This is the Welcome page.")
171
+
172
+ # Display username and logout button on every page
173
+ st.sidebar.write(f"Welcome, {st.session_state['username']}")
174
+ if st.sidebar.button("Logout"):
175
+ logout()
176
+ st.rerun()
177
+
178
+
179
+ if __name__ == "__main__":
180
+ main()
pages/About.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def show_about():
4
+ if st.session_state["authenticated"]:
5
+ st.title("About")
6
+ # Add your About page content here
7
+ st.write("This is the About page.")
8
+ else:
9
+ st.write("You are not authenticated. Please log in to access this page.")
10
+
11
+ if st.session_state["authenticated"]:
12
+ show_about()
13
+ else:
14
+ if not st.session_state["is_starting"]:
15
+ st.write("You are not authenticated. Please log in to access this page.")
pages/Multimodal.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def show_multimodal():
4
+ st.title("Multimodal")
5
+ # Add your Multimodal page content here
6
+ st.write("This is the Multimodal page.")
7
+
8
+ if st.session_state["authenticated"]:
9
+ show_multimodal()
10
+ else:
11
+ if not st.session_state["is_starting"]:
12
+ st.write("You are not authenticated. Please log in to access this page.")
pages/Settings.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def show_settings():
4
+ st.title("Settings")
5
+ # Add your Settings page content here
6
+ st.write("This is the Settings page.")
pages/Text_prompt.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def show_text_prompt():
4
+ st.title("Text Prompt")
5
+ # Add your Text Prompt page content here
6
+ st.write("This is the Text Prompt page.")
pages/__pycache__/About.cpython-313.pyc ADDED
Binary file (873 Bytes). View file
 
pages/__pycache__/Multimodal.cpython-313.pyc ADDED
Binary file (757 Bytes). View file
 
pages/__pycache__/Settings.cpython-313.pyc ADDED
Binary file (450 Bytes). View file
 
pages/__pycache__/Text_prompt.cpython-313.pyc ADDED
Binary file (462 Bytes). View file
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ passlib
3
+ bcrypt==3.2.0
users.db ADDED
Binary file (8.19 kB). View file