Is there a way to hide my login screen after the user authenticates?

Is there a way to hide my login screen after the user authenticates?

This is my code at the moment:


import streamlit as st

import pandas as pd

import hashlib

import funcoes

Security

def make_hashes(password):
return hashlib.sha256(str.encode(password)).hexdigest()

def check_hashes(password,hashed_text):
if make_hashes(password) == hashed_text:
return hashed_text
return False

#DB Management

import sqlite3

conn = sqlite3.connect(‘data.db’)

c = conn.cursor()

DB Functions

def create_usertable():
c.execute(‘CREATE TABLE IF NOT EXISTS userstable(username TEXT,password TEXT)’)

def add_userdata(username,password):
c.execute(‘INSERT INTO userstable(username,password) VALUES (?,?)’,(username,password))
conn.commit()

def login_user(username,password):
c.execute(‘SELECT * FROM userstable WHERE username =? AND password = ?’,(username,password))
data = c.fetchall()
return data

def view_all_users():
c.execute(‘SELECT * FROM userstable’)
data = c.fetchall()
return data

#Main Function

def main():

st.title("-Sistema Engenharia Field-")

menu = ["Login","SignUp","Data"]

choice = st.sidebar.selectbox("Menu",menu)

if choice == "Login":        #Login Screen
    
    st.subheader("Login Section")

    username = st.text_input("User Name")
    
    password = st.text_input("Password",type='password')

    if st.checkbox("Login"):

        create_usertable()
        
        hashed_pswd = make_hashes(password)

        result = login_user(username,check_hashes(password,hashed_pswd))
        
        if result:
                
            st.success("Logged In as {}".format(username))

            #funcoes.test()
            
        else:
        
            st.warning("Incorrect Username/Password")


elif choice == "SignUp":
    st.subheader("Create New Account")
    new_user = st.text_input("Username")
    new_password = st.text_input("Password",type='password')

    if st.button("Signup"):
        create_usertable()
        add_userdata(new_user,make_hashes(new_password))
        st.success("You have successfully created a valid Account")
        st.info("Go to Login Menu to login")

if name == ‘main’:
main()

This is what it looks like

Hi @Leandro_Junior, after you show the login success message, you need to redirect to another page. There are a couple of ways to do this: (a) using the experimental rerun or (b) the switch page function in Streamlit extras

Cheers

1 Like

I’ll Try the switch page function, thanks !!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.