Spaces:
Running
Running
Create login.py
Browse files
login.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
|
4 |
+
|
5 |
+
hardcodedlogin_user={
|
6 |
+
|
7 |
+
"usernames":["admin"],
|
8 |
+
"passwords":["123"]
|
9 |
+
|
10 |
+
}
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
def authenticate_user(username,password):
|
15 |
+
|
16 |
+
if username in hardcodedlogin_user["usernames"] and password in hardcodedlogin_user["passwords"]:
|
17 |
+
return True
|
18 |
+
else:
|
19 |
+
return False
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
def LOGIN():
|
25 |
+
|
26 |
+
st.text("Authentication System")
|
27 |
+
#with st.form("login_form"):
|
28 |
+
username = st.text_input("Username")
|
29 |
+
password = st.text_input("Password", type="password")
|
30 |
+
#login_button = st.form_submit_button("Login")
|
31 |
+
|
32 |
+
if st.button("login_button"):
|
33 |
+
if username and password:
|
34 |
+
status = authenticate_user(username, password)
|
35 |
+
if status==True:
|
36 |
+
st.session_state.logged_in = True
|
37 |
+
st.session_state.username = username
|
38 |
+
st.rerun()
|
39 |
+
else:
|
40 |
+
st.error(message)
|
41 |
+
else:
|
42 |
+
st.warning("Please enter both username and password")
|