Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PYTHON_FILES = `(find . -iname "*.py" -not -path "./.venv/*")`

clean:
rm -rf .venv/

install: # Install project locally
poetry install --sync

install-dev: # Install project locally with dev dependencies
poetry install --sync --with dev

install-clean: clean install ## Clear and install dependencies

format: ## Format code using ruff format and cargo fmt
poetry run ruff format $(PYTHON_FILES)

format-check: ## Check code format using ruff format and cargo fmt
poetry run ruff format --check $(PYTHON_FILES)

lint: ## Run all linters with automated fix
poetry run ruff --fix $(PYTHON_FILES)

lint-check: ## Run all linters
poetry run ruff $(PYTHON_FILES)


help: ## Description of the Makefile commands
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}'
1,348 changes: 1,348 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions poetry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[virtualenvs]
create = true
in-project = true
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[tool.poetry]
name = "streamlit-authenticator"
version = "0.2.3"
description = "A secure authentication module to validate user credentials in a Streamlit application."
authors = ["Mohammad Khorasani <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/mkhorasani/Streamlit-Authenticator"
keywords = ["Python", "Streamlit", "Authentication", "Components"]

[tool.poetry.dependencies]
python = "^3.10"
PyJWT = "^2.3.0"
bcrypt = "^3.1.7"
streamlit = "^1.18.0"
extra-streamlit-components = "^0.1.60"
pyyaml = "^6.0.1"

[tool.poetry.group.dev.dependencies]
ruff = "^0.1.9"

[tool.poetry.group.dev]
optional = true

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
31 changes: 0 additions & 31 deletions setup.py

This file was deleted.

62 changes: 35 additions & 27 deletions streamlit_authenticator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import yaml
import streamlit as st
from yaml.loader import SafeLoader
import streamlit.components.v1 as components

from .hasher import Hasher
from .authenticate import Authenticate

_RELEASE = True
Expand All @@ -12,74 +10,84 @@
# hashed_passwords = Hasher(['abc', 'def']).generate()

# Loading config file
with open('../config.yaml') as file:
with open("../config.yaml") as file:
config = yaml.load(file, Loader=SafeLoader)

# Creating the authenticator object
authenticator = Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
config["credentials"],
config["cookie"]["name"],
config["cookie"]["key"],
config["cookie"]["expiry_days"],
config["preauthorized"],
)

# creating a login widget
authenticator.login('Login', 'main')
authenticator.login("Login", "main")
if st.session_state["authentication_status"]:
authenticator.logout('Logout', 'main')
authenticator.logout("Logout", "main")
st.write(f'Welcome *{st.session_state["name"]}*')
st.title('Some content')
st.title("Some content")
elif st.session_state["authentication_status"] is False:
st.error('Username/password is incorrect')
st.error("Username/password is incorrect")
elif st.session_state["authentication_status"] is None:
st.warning('Please enter your username and password')
st.warning("Please enter your username and password")

# Creating a password reset widget
if st.session_state["authentication_status"]:
try:
if authenticator.reset_password(st.session_state["username"], 'Reset password'):
st.success('Password modified successfully')
if authenticator.reset_password(
st.session_state["username"], "Reset password"
):
st.success("Password modified successfully")
except Exception as e:
st.error(e)

# Creating a new user registration widget
try:
if authenticator.register_user('Register user', preauthorization=False):
st.success('User registered successfully')
if authenticator.register_user("Register user", preauthorization=False):
st.success("User registered successfully")
except Exception as e:
st.error(e)

# Creating a forgot password widget
try:
username_forgot_pw, email_forgot_password, random_password = authenticator.forgot_password('Forgot password')
(
username_forgot_pw,
email_forgot_password,
random_password,
) = authenticator.forgot_password("Forgot password")
if username_forgot_pw:
st.success('New password sent securely')
st.success("New password sent securely")
# Random password to be transferred to user securely
else:
st.error('Username not found')
st.error("Username not found")
except Exception as e:
st.error(e)

# Creating a forgot username widget
try:
username_forgot_username, email_forgot_username = authenticator.forgot_username('Forgot username')
username_forgot_username, email_forgot_username = authenticator.forgot_username(
"Forgot username"
)
if username_forgot_username:
st.success('Username sent securely')
st.success("Username sent securely")
# Username to be transferred to user securely
else:
st.error('Email not found')
st.error("Email not found")
except Exception as e:
st.error(e)

# Creating an update user details widget
if st.session_state["authentication_status"]:
try:
if authenticator.update_user_details(st.session_state["username"], 'Update user details'):
st.success('Entries updated successfully')
if authenticator.update_user_details(
st.session_state["username"], "Update user details"
):
st.success("Entries updated successfully")
except Exception as e:
st.error(e)

# Saving config file
with open('../config.yaml', 'w') as file:
yaml.dump(config, file, default_flow_style=False)
with open("../config.yaml", "w") as file:
yaml.dump(config, file, default_flow_style=False)
Loading