Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
A streamlit component that creates a user login form connected to a Supabase DB. It lets users create a new username and password, login to an existing account, or login as an anonymous guest.
A Streamlit authentication component that creates a user login form connected to a Supabase DB.
st-login-form
pip install st-login-form
CREATE TABLE users (
username text not null default ''::text,
password text not null,
constraint users_pkey primary key (username),
constraint users_username_key unique (username),
constraint users_password_check check (
(
length(
trim(
both
from
password
)
) > 1
)
),
constraint users_username_check check (
(
length(
trim(
both
from
username
)
) > 1
)
)
) tablespace pg_default;
On authentication, login_form()
sets the st.session_state['authenticated']
to True
. This also collapses and disables the login form.
st.session_state['username']
is set to the provided username for a new or existing user, and to None
for guest login.
import streamlit as st
from st_login_form import login_form
client = login_form()
if st.session_state["authenticated"]:
if st.session_state["username"]:
st.success(f"Welcome {st.session_state['username']}")
...
else:
st.success("Welcome guest")
...
else:
st.error("Not authenticated")
Plaintext password for a user is automatically hashed during a login attempt.
To bulk-update all existing plaintext passwords in the table, use the hash_current_passwords()
method.
login_form()
def login_form(
*,
title: str = "Authentication",
user_tablename: str = "users",
username_col: str = "username",
password_col: str = "password",
constrain_password: bool = True,
create_title: str = "Create new account :baby: ",
login_title: str = "Login to existing account :prince: ",
allow_guest: bool = True,
allow_create: bool = True,
guest_title: str = "Guest login :ninja: ",
create_username_label: str = "Create a unique username",
create_username_placeholder: str = None,
create_username_help: str = None,
create_password_label: str = "Create a password",
create_password_placeholder: str = None,
create_password_help: str = "Password cannot be recovered if lost",
create_submit_label: str = "Create account",
create_success_message: str = "Account created and logged-in :tada:",
login_username_label: str = "Enter your unique username",
login_username_placeholder: str = None,
login_username_help: str = None,
login_password_label: str = "Enter your password",
login_password_placeholder: str = None,
login_password_help: str = None,
login_submit_label: str = "Login",
login_success_message: str = "Login succeeded :tada:",
login_error_message: str = "Wrong username/password :x: ",
password_constraint_check_fail_message: str = "Password must contain at least 8 characters, including one uppercase letter, one lowercase letter, one number, and one special character (`@$!%*?&_^#- `).",
guest_submit_label: str = "Guest login",
) -> Client:
"""Creates a user login form in Streamlit apps.
Connects to a Supabase DB using `SUPABASE_URL` and `SUPABASE_KEY` Streamlit secrets.
Sets `session_state["authenticated"]` to True if the login is successful.
Sets `session_state["username"]` to provided username or new or existing user, and to `None` for guest login.
Arguments:
title (str): The title of the login form. Default is "Authentication".
user_tablename (str): The name of the table in the database that stores user information. Default is "users".
username_col (str): The name of the column in the user table that stores usernames. Default is "username".
password_col (str): The name of the column in the user table that stores passwords. Default is "password".
constrain_password (bool): Whether to enforce password constraints (at least 8 characters, including one uppercase letter, one lowercase letter, one number, and one special character (`@$!%*?&_^#- `). Default is True.
create_title (str): The title of the create new account tab. Default is "Create new account :baby: ".
login_title (str): The title of the login to existing account tab. Default is "Login to existing account :prince: ".
allow_guest (bool): Whether to allow guest login. Default is True.
allow_create (bool): Whether to allow creating new accounts. Default is True.
guest_title (str): The title of the guest login tab. Default is "Guest login :ninja: ".
create_username_label (str): The label for the create username input field. Default is "Create a unique username".
create_username_placeholder (str): The placeholder text for the create username input field. Default is None.
create_username_help (str): The help text for the create username input field. Default is None.
create_password_label (str): The label for the create password input field. Default is "Create a password".
create_password_placeholder (str): The placeholder text for the create password input field. Default is None.
create_password_help (str): The help text for the create password input field. Default is "Password cannot be recovered if lost".
create_submit_label (str): The label for the create account submit button. Default is "Create account".
create_success_message (str): The success message displayed after creating a new account. Default is "Account created and logged-in :tada:".
login_username_label (str): The label for the login username input field. Default is "Enter your unique username".
login_username_placeholder (str): The placeholder text for the login username input field. Default is None.
login_username_help (str): The help text for the login username input field. Default is None.
login_password_label (str): The label for the login password input field. Default is "Enter your password".
login_password_placeholder (str): The placeholder text for the login password input field. Default is None.
login_password_help (str): The help text for the login password input field. Default is None.
login_submit_label (str): The label for the login submit button. Default is "Login".
login_success_message (str): The success message displayed after a successful login. Default is "Login succeeded :tada:".
login_error_message (str): The error message displayed when the username or password is incorrect. Default is "Wrong username/password :x: ".
password_constraint_check_fail_message (str): The error message displayed when the password does not meet the constraints. Default is "Password must contain at least 8 characters, including one uppercase letter, one lowercase letter, one number, and one special character (`@$!%*?&_^#- `).".
guest_submit_label (str): The label for the guest login button. Default is "Guest login".
Returns:
Supabase.client: The client instance for performing downstream supabase operations.
"""
hash_current_passwords()
def hash_current_passwords(
user_tablename: str = "users",
username_col: str = "username",
password_col: str = "password",
) -> None:
"""Hashes all current plaintext passwords stored in a database table (in-place)."""
Here are some features that are planned for future releases across the library and demo app. If you want to contribute to any of these features, feel free to open a PR!
Your feedback and contributions can help shape the future of Streamlit Login Form. If you have ideas or features you'd like to see, let's collaborate!
Love Streamlit Login Form? Here's how you can show your support:
Thank you for supporting Streamlit Login Form!
FAQs
A streamlit component that creates a user login form connected to a Supabase DB. It lets users create a new username and password, login to an existing account, or login as an anonymous guest.
We found that st-login-form demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.