# Streamlit-Authenticator [](https://pepy.tech/project/streamlit-authenticator)
A secure authentication module to validate user credentials in a Streamlit application.
## Installation
Streamlit-Authenticator-Sheets is distributed via [PyPI](https://pypi.org/project/streamlit-authenticator/):
```python
pip install streamlit-authenticator-sheets
```
## Example
Using Streamlit-Authenticator_Sheets is as simple as importing the module and calling it to verify your predefined users' credentials.
```python
import streamlit as st
import streamlit_authenticator as stauth
```
### 1. Hashing Passwords
* Initially define your users' names, usernames, plain text passwords, and reauthentication cookie settings in a YAML configuration file.
```python
credentials:
names: ['John Smith', 'Rebecca Briggs']
usernames: ['jsmith', 'rbriggs']
passwords: ['123', '456'] # To be replaced with hashed passwords
cookie:
name: 'some_cookie_name'
key: 'some_signature_key'
expiry_days: 30
```
* Then use the Hasher module to convert the plain text passwords to hashed passwords.
```python
hashed_passwords = stauth.Hasher(['123', '456']).generate()
```
Finally replace the plain text passwords in the configuration file with the hashed passwords.
### 2. Creating Login Widget
* Subsequently import the configuration file into your script to create an authentication object. Here you will need to enter a name for the JWT cookie that will be stored on the client's browser and used to reauthenticate the user without re-entering their credentials. In addition, you will need to provide any random key to be used to hash the cookie's signature. Finally, you will need to specify the number of days to use the cookie for, if you do not require passwordless reauthentication, you may set this to 0.
```python
with open('../config.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
config['credentials']['names'],
config['credentials']['usernames'],
config['credentials']['passwords'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days']
)
```
* Then finally render the login module as follows. Here you will need to provide a name for the login form, and specify where the form should be located i.e. main body or sidebar (will default to main body).
```python
name, authentication_status, username = authenticator.login('Login', 'main')
```

### 3. Authenticating Users
* You can then use the returned name and authentication status to allow your verified user to proceed to any restricted content. In addition, you have the ability to add an optional logout button at any location on your main body or sidebar (will default to main body).
```python
if authentication_status:
authenticator.logout('Logout', 'main')
st.write(f'Welcome *{name}*')
st.title('Some content')
elif authentication_status == False:
st.error('Username/password is incorrect')
elif authentication_status == None:
st.warning('Please enter your username and password')
```
* Should you require access to the persistent name, authentication status, and username variables, you may retrieve them through Streamlit's session state using **st.session_state['name']**, **st.session_state['authentication_status']**, and **st.session_state['username']**. This way you can use Streamlit-Authenticator to authenticate users across multiple pages.
```python
if st.session_state['authentication_status']:
authenticator.logout('Logout', 'main')
st.write(f'Welcome *{st.session_state["name"]}*')
st.title('Some content')
elif st.session_state['authentication_status'] == False:
st.error('Username/password is incorrect')
elif st.session_state['authentication_status'] == None:
st.warning('Please enter your username and password')
```

Or prompt an unverified user to enter a correct username and password.

Please note that logging out will revert the authentication status to **None** and will delete the associated reauthentication cookie as well.
## Credits
- Mohamed Abdou for the highly versatile cookie manager in [Extra-Streamlit-Components](https://github.com/Mohamed-512/Extra-Streamlit-Components).
Raw data
{
"_id": null,
"home_page": "https://github.com/JoseLuisFFDT/streamlit-authenticator-sheets",
"name": "streamlit-authenticator-sheets",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "Python, Streamlit, Authentication, Components",
"author": "Jos\u00e9 Luis Fdez-Figueroa",
"author_email": "joseluidfft01@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/88/85/9a8b1b2406b3b62ad72bee8b04219769ca8e9e41b37abe46673858319cf9/streamlit_authenticator_sheets-0.1.7.tar.gz",
"platform": null,
"description": "# Streamlit-Authenticator [](https://pepy.tech/project/streamlit-authenticator)\r\nA secure authentication module to validate user credentials in a Streamlit application.\r\n\r\n## Installation\r\n\r\nStreamlit-Authenticator-Sheets is distributed via [PyPI](https://pypi.org/project/streamlit-authenticator/):\r\n\r\n```python\r\npip install streamlit-authenticator-sheets\r\n```\r\n\r\n## Example\r\n\r\nUsing Streamlit-Authenticator_Sheets is as simple as importing the module and calling it to verify your predefined users' credentials.\r\n\r\n```python\r\nimport streamlit as st\r\nimport streamlit_authenticator as stauth\r\n```\r\n\r\n### 1. Hashing Passwords\r\n\r\n* Initially define your users' names, usernames, plain text passwords, and reauthentication cookie settings in a YAML configuration file.\r\n\r\n```python\r\ncredentials:\r\n names: ['John Smith', 'Rebecca Briggs']\r\n usernames: ['jsmith', 'rbriggs']\r\n passwords: ['123', '456'] # To be replaced with hashed passwords\r\ncookie:\r\n name: 'some_cookie_name'\r\n key: 'some_signature_key'\r\n expiry_days: 30\r\n```\r\n\r\n* Then use the Hasher module to convert the plain text passwords to hashed passwords.\r\n\r\n```python\r\nhashed_passwords = stauth.Hasher(['123', '456']).generate()\r\n```\r\n\r\nFinally replace the plain text passwords in the configuration file with the hashed passwords.\r\n\r\n### 2. Creating Login Widget\r\n\r\n* Subsequently import the configuration file into your script to create an authentication object. Here you will need to enter a name for the JWT cookie that will be stored on the client's browser and used to reauthenticate the user without re-entering their credentials. In addition, you will need to provide any random key to be used to hash the cookie's signature. Finally, you will need to specify the number of days to use the cookie for, if you do not require passwordless reauthentication, you may set this to 0.\r\n\r\n```python\r\nwith open('../config.yaml') as file:\r\n config = yaml.load(file, Loader=SafeLoader)\r\n\r\nauthenticator = stauth.Authenticate(\r\n config['credentials']['names'],\r\n config['credentials']['usernames'],\r\n config['credentials']['passwords'],\r\n config['cookie']['name'],\r\n config['cookie']['key'],\r\n config['cookie']['expiry_days']\r\n)\r\n```\r\n\r\n* Then finally render the login module as follows. Here you will need to provide a name for the login form, and specify where the form should be located i.e. main body or sidebar (will default to main body).\r\n\r\n```python\r\nname, authentication_status, username = authenticator.login('Login', 'main')\r\n```\r\n\r\n\r\n### 3. Authenticating Users\r\n\r\n* You can then use the returned name and authentication status to allow your verified user to proceed to any restricted content. In addition, you have the ability to add an optional logout button at any location on your main body or sidebar (will default to main body).\r\n\r\n```python\r\nif authentication_status:\r\n authenticator.logout('Logout', 'main')\r\n st.write(f'Welcome *{name}*')\r\n st.title('Some content')\r\nelif authentication_status == False:\r\n st.error('Username/password is incorrect')\r\nelif authentication_status == None:\r\n st.warning('Please enter your username and password')\r\n```\r\n\r\n* Should you require access to the persistent name, authentication status, and username variables, you may retrieve them through Streamlit's session state using **st.session_state['name']**, **st.session_state['authentication_status']**, and **st.session_state['username']**. This way you can use Streamlit-Authenticator to authenticate users across multiple pages.\r\n\r\n```python\r\nif st.session_state['authentication_status']:\r\n authenticator.logout('Logout', 'main')\r\n st.write(f'Welcome *{st.session_state[\"name\"]}*')\r\n st.title('Some content')\r\nelif st.session_state['authentication_status'] == False:\r\n st.error('Username/password is incorrect')\r\nelif st.session_state['authentication_status'] == None:\r\n st.warning('Please enter your username and password')\r\n```\r\n\r\n\r\n\r\nOr prompt an unverified user to enter a correct username and password.\r\n\r\n\r\n\r\nPlease note that logging out will revert the authentication status to **None** and will delete the associated reauthentication cookie as well.\r\n\r\n## Credits\r\n- Mohamed Abdou for the highly versatile cookie manager in [Extra-Streamlit-Components](https://github.com/Mohamed-512/Extra-Streamlit-Components).\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A secure authentication module to validate user credentials in a Streamlit application using the Google Sheets API and the library of streamlit authenticator.",
"version": "0.1.7",
"project_urls": {
"Homepage": "https://github.com/JoseLuisFFDT/streamlit-authenticator-sheets"
},
"split_keywords": [
"python",
" streamlit",
" authentication",
" components"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6b49fede786fdd1e4ddf29a1d70861bd8e850ff5f01d83bca089967c28e65a8e",
"md5": "a25122a0ea7fb1806aa9db5cf8518004",
"sha256": "6134d72e4eac89624d1f067573d758208183e3456d99ad22e42f8b07966f3667"
},
"downloads": -1,
"filename": "streamlit_authenticator_sheets-0.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a25122a0ea7fb1806aa9db5cf8518004",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 11506,
"upload_time": "2025-02-09T17:55:35",
"upload_time_iso_8601": "2025-02-09T17:55:35.400193Z",
"url": "https://files.pythonhosted.org/packages/6b/49/fede786fdd1e4ddf29a1d70861bd8e850ff5f01d83bca089967c28e65a8e/streamlit_authenticator_sheets-0.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "88859a8b1b2406b3b62ad72bee8b04219769ca8e9e41b37abe46673858319cf9",
"md5": "c8ae1292606001ed954294184c409eff",
"sha256": "e0c099cdc5eb9d4e2b08558196e87db5eca43507c0df6e4889ca18c52ee15f2c"
},
"downloads": -1,
"filename": "streamlit_authenticator_sheets-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "c8ae1292606001ed954294184c409eff",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 12466,
"upload_time": "2025-02-09T17:55:40",
"upload_time_iso_8601": "2025-02-09T17:55:40.282897Z",
"url": "https://files.pythonhosted.org/packages/88/85/9a8b1b2406b3b62ad72bee8b04219769ca8e9e41b37abe46673858319cf9/streamlit_authenticator_sheets-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-09 17:55:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "JoseLuisFFDT",
"github_project": "streamlit-authenticator-sheets",
"github_not_found": true,
"lcname": "streamlit-authenticator-sheets"
}