File size: 1,087 Bytes
d1da800
 
 
 
 
 
 
63a7f01
 
cb4004b
 
63a7f01
d1da800
 
 
 
 
 
 
 
63a7f01
d1da800
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import streamlit as st

def login():
    """
    Display a login form and return True if login is successful, False otherwise.
    """
    st.title("Login to Data Science Course App")

    #usernames
    usernames = ["admin", "student", "manxiii","zhu","WK","ruixi"]
    passwords = ["admin", "123", "manxi123","zhu123","WK123","ruixi123"]

    # Create a form for login
    with st.form("login_form"):
        username = st.text_input("Username")
        password = st.text_input("Password", type="password")
        submit_button = st.form_submit_button("Login")
        
        if submit_button:
            # Check credentials (test account)
            if username in usernames and password in passwords:
                # Store login state in session
                st.session_state.logged_in = True
                st.session_state.username = username
                st.success("Login successful!")
                st.rerun()
            else:
                st.error("Invalid username or password. Please try again.")
    
    return st.session_state.get("logged_in", False)