streamlit-authenticator


Namestreamlit-authenticator JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/mkhorasani/Streamlit-Authenticator
SummaryA secure authentication module to validate user credentials in a Streamlit application.
upload_time2024-03-26 19:27:42
maintainerNone
docs_urlNone
authorMohammad Khorasani
requires_python>=3.6
licenseNone
keywords python streamlit authentication components
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="https://raw.githubusercontent.com/mkhorasani/Streamlit-Authenticator/main/graphics/logo.png" alt="Streamlit Authenticator logo" style="margin-top:50px;width:450px"></img>
<!--- [![Downloads](https://pepy.tech/badge/streamlit-authenticator)](https://pepy.tech/project/streamlit-authenticator) --->
<!--- [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/khorasani) --->

**A secure authentication module to validate user credentials in a Streamlit application.**
<br/><br/><br/>
<a href="http://tinyurl.com/2p8mw32d"><img src="https://raw.githubusercontent.com/mkhorasani/streamlit_authenticator_test/main/Web%20App%20Web%20Dev%20with%20Streamlit%20-%20Cover.png" width="300" height="450">

###### _To learn more please refer to my book [Web Application Development with Streamlit](http://tinyurl.com/2p8mw32d)._


## Installation

Streamlit-Authenticator is distributed via [PyPI](https://pypi.org/project/streamlit-authenticator/):

```python
pip install streamlit-authenticator
```

## Example

Using Streamlit-Authenticator 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. Creating a configuration file

* Initially create a YAML configuration file and define your user's credentials: including names, usernames, and passwords (plain text passwords will be hashed automatically).
* In addition, enter a name, random key, and number of days to expiry for a JWT cookie that will be stored on the client's browser to enable password-less re-authentication. If you do not require re-authentication, you may set the number of days to expiry to 0.
* Finally, define a list of pre-authorized emails of users who can register and add their credentials to the configuration file with the use of the **register_user** widget.
* **_Please remember to update the config file (as shown in step 9) after you use the reset_password, register_user, forgot_password, or update_user_details widgets._**

```python
credentials:
  usernames:
    jsmith:
      email: jsmith@gmail.com
      failed_login_attempts: 0 # Will be managed automatically
      logged_in: False # Will be managed automatically
      name: John Smith
      password: abc # Will be hashed automatically
    rbriggs:
      email: rbriggs@gmail.com
      failed_login_attempts: 0 # Will be managed automatically
      logged_in: False # Will be managed automatically
      name: Rebecca Briggs
      password: def # Will be hashed automatically
cookie:
  expiry_days: 30
  key: some_signature_key # Must be string
  name: some_cookie_name
pre-authorized:
  emails:
  - melsby@gmail.com
```

_Please note that the 'logged_in' field corresponding to each user's log-in status will be added automatically._

### 2. Creating a login widget

* Subsequently import the configuration file into your script and create an authentication object.

```python
import yaml
from yaml.loader import SafeLoader

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

authenticator = stauth.Authenticate(
    config['credentials'],
    config['cookie']['name'],
    config['cookie']['key'],
    config['cookie']['expiry_days'],
    config['pre-authorized']
)
```

> ### Authenticate
> #### Parameters:
>  - **credentials:** _dict_
>    - Provides the usernames, names, passwords, and emails, and other user data.
>  - **cookie_name:** _str_
>    - Specifies the name of the JWT cookie stored on the client's browser for password-less re-authentication.
>  - **cookie_key:** _str_
>    - Specifies the key that will be used to hash the signature of the re-authentication cookie.
>  - **cookie_expiry_days:** _float, default 30.0_
>    - Specifies the number of days before the re-authentication cookie automatically expires on the client's browser.
>  - **pre-authorized:** _list, default None_
>    - Provides the list of emails of unregistered users who are authorized to register.
>  - **validator:** _object, default None_
>    - Provides a validator object that will check the validity of the username, name, and email fields.

* Then render the login module as follows.

```python
authenticator.login()
```

> ### Authenticate.login
> #### Parameters:
>  - **location:** _str, {'main', 'sidebar'}, default 'main'_
>    - Specifies the location of the login widget.
>  - **max_concurrent_users:** _int, default None_
>    - Limits the number of concurrent users. If not specified there will be no limit to the number of users.
>  - **max_login_attempts:** _int, default None_
>    - Limits the number of failed login attempts. If not specified there will be no limit to the number of failed login attempts.
>  - **fields:** _dict, default {'Form name':'Login', 'Username':'Username', 'Password':'Password', 'Login':'Login'}_
>    - Customizes the text of headers, buttons and other fields.
>  - **clear_on_submit:** _bool, default False_
>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
> #### Returns:
> - _str_
>   - Name of the authenticated user.
> - _bool_
>   - Status of authentication, None: no credentials entered, False: incorrect credentials, True: correct credentials.
> - _str_
>   - Username of the authenticated user.

![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/login_form.JPG)

### 3. Authenticating users

* You can then retrieve the name, authentication status, and username from Streamlit's session state using **st.session_state["name"]**, **st.session_state["authentication_status"]**, and **st.session_state["username"]** to allow a verified user to proceed to any restricted content.
* You may also render a logout button, or may choose not to render the button if you only need to implement the logout logic programmatically.
* The optional **key** parameter for the logout button should be used with multi-page applications to prevent Streamlit from throwing duplicate key errors.

```python
if st.session_state["authentication_status"]:
    authenticator.logout()
    st.write(f'Welcome *{st.session_state["name"]}*')
    st.title('Some content')
elif st.session_state["authentication_status"] is False:
    st.error('Username/password is incorrect')
elif st.session_state["authentication_status"] is None:
    st.warning('Please enter your username and password')
```

> ### Authenticate.logout
> #### Parameters:
>  - **button_name:** _str, default 'Logout'_
>    - Customizes the button name.
>  - **location:** _str, {'main', 'sidebar','unrendered'}, default 'main'_
>    - Specifies the location of the logout button. If 'unrendered' is passed, the logout logic will be executed without rendering the button.
>  - **key:** _str, default None_
>    - Unique key that should be used in multi-page applications.

![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/logged_in.JPG)

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

![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/incorrect_login.JPG)

* You may also retrieve the number of failed login attempts a user has made by accessing **st.session_state['failed_login_attempts']** which returns a dictionary with the username as key and the number of failed attempts as the value.

### 4. Creating a reset password widget

* You may use the **reset_password** widget to allow a logged in user to modify their password as shown below.

```python
if st.session_state["authentication_status"]:
    try:
        if authenticator.reset_password(st.session_state["username"]):
            st.success('Password modified successfully')
    except Exception as e:
        st.error(e)
```

> ### Authenticate.reset_password
> #### Parameters:
>  - **username:** _str_
>    - Specifies the username of the user to reset the password for.
>  - **location:** _str, {'main', 'sidebar'}, default 'main'_
>    - Specifies the location of the reset password widget.
>  - **fields:** _dict, default {'Form name':'Reset password', 'Current password':'Current password', 'New password':'New password', 'Repeat password': 'Repeat password', 'Reset':'Reset'}_
>    - Customizes the text of headers, buttons and other fields.
>  - **clear_on_submit:** _bool, default False_
>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
> #### Returns::
> - _bool_
>   - Status of resetting the password.

![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/reset_password.JPG)

_Please remember to update the config file (as shown in step 9) after you use this widget._

### 5. Creating a new user registration widget

* You may use the **register_user** widget to allow a user to sign up to your application as shown below. If you require the user to be pre-authorized, set the **pre-authorization** argument to True and add their email to the **pre-authorized** list in the configuration file. Once they have registered, their email will be automatically removed from the **pre-authorized** list in the configuration file. Alternatively, to allow anyone to sign up, set the **pre-authorization** argument to False.

```python
try:
    email_of_registered_user, username_of_registered_user, name_of_registered_user = authenticator.register_user(pre_authorization=False)
    if email_of_registered_user:
        st.success('User registered successfully')
except Exception as e:
    st.error(e)
```

> ### Authenticate.register_user
> #### Parameters:
>  - **location:** _str, {'main', 'sidebar'}, default 'main'_
>    - Specifies the location of the register user widget.
>  - **pre-authorization:** _bool, default True_
>    - Specifies the pre-authorization requirement, True: user must be pre-authorized to register, False: any user can register.
>  - **domains:** _list, default None_
>    - Specifies the required list of domains a new email must belong to i.e. ['gmail.com', 'yahoo.com'], list: the required list of domains, None: any domain is allowed.
>  - **fields:** _dict, default {'Form name':'Register user', 'Email':'Email', 'Username':'Username', 'Password':'Password', 'Repeat password':'Repeat password', 'Register':'Register'}_
>    - Customizes the text of headers, buttons and other fields.
>  - **clear_on_submit:** _bool, default False_
>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
> #### Returns:
> - _str_
>   - Email associated with the new user.
> - _str_
>   - Username associated with the new user.
> - _str_
>   - Name associated with the new user.

![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/register_user.JPG)

_Please remember to update the config file (as shown in step 9) after you use this widget._

### 6. Creating a forgot password widget

* You may use the **forgot_password** widget to allow a user to generate a new random password. This password will be automatically hashed and saved in the configuration file. The widget will return the username, email, and new random password which the developer should then transfer to the user securely.

```python
try:
    username_of_forgotten_password, email_of_forgotten_password, new_random_password = authenticator.forgot_password()
    if username_of_forgotten_password:
        st.success('New password to be sent securely')
        # The developer should securely transfer the new password to the user.
    elif username_of_forgotten_password == False:
        st.error('Username not found')
except Exception as e:
    st.error(e)
```

> ### Authenticate.forgot_password
> #### Parameters
>  - **location:** _str, {'main', 'sidebar'}, default 'main'_
>    - Specifies the location of the forgot password widget.
>  - **fields:** _dict, default {'Form name':'Forgot password', 'Username':'Username', 'Submit':'Submit'}_
>    - Customizes the text of headers, buttons and other fields.
>  - **clear_on_submit:** _bool, default False_
>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
> #### Returns:
> - _str_
>   - Username associated with the forgotten password.
> - _str_
>   - Email associated with the forgotten password.
> - _str_
>   - New plain text password that should be transferred to the user securely.

![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/forgot_password.JPG)

_Please remember to update the config file (as shown in step 9) after you use this widget._

### 7. Creating a forgot username widget

* You may use the **forgot_username** widget to allow a user to retrieve their forgotten username. The widget will return the username and email which the developer should then transfer to the user securely.

```python
try:
    username_of_forgotten_username, email_of_forgotten_username = authenticator.forgot_username()
    if username_of_forgotten_username:
        st.success('Username to be sent securely')
        # The developer should securely transfer the username to the user.
    elif username_of_forgotten_username == False:
        st.error('Email not found')
except Exception as e:
    st.error(e)
```

> ### Authenticate.forgot_username
> #### Parameters
>  - **location:** _str, {'main', 'sidebar'}, default 'main'_
>    - Specifies the location of the forgot username widget.
>  - **fields:** _dict, default {'Form name':'Forgot username', 'Email':'Email', 'Submit':'Submit'}_
>    - Customizes the text of headers, buttons and other fields.
>  - **clear_on_submit:** _bool, default False_
>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
> #### Returns:
> - _str_
>   - Forgotten username that should be transferred to the user securely.
> - _str_
>   - Email associated with the forgotten username.

![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/forgot_username.JPG)

### 8. Creating an update user details widget

* You may use the **update_user_details** widget to allow a logged in user to update their name and/or email. The widget will automatically save the updated details in both the configuration file and re-authentication cookie.

```python
if st.session_state["authentication_status"]:
    try:
        if authenticator.update_user_details(st.session_state["username"]):
            st.success('Entries updated successfully')
    except Exception as e:
        st.error(e)
```

> ### Authenticate.update_user_details
> #### Parameters
>  - **username:** _str_
>    - Specifies the username of the user to update user details for.
>  - **location:** _str, {'main', 'sidebar'}, default 'main'_
>    - Specifies the location of the update user details widget.
>  - **fields:** _dict, default {'Form name':'Update user details', 'Field':'Field', 'Name':'Name', 'Email':'Email', 'New value':'New value', 'Update':'Update'}_
>    - Customizes the text of headers, buttons and other fields.
>  - **clear_on_submit:** _bool, default False_
>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.
> #### Returns:
> - _bool_
>   - Status of updating the user details.

![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/update_user_details.JPG)

_Please remember to update the config file (as shown in step 9) after you use this widget._

### 9. Updating the configuration file

* Please ensure that the configuration file is re-saved anytime the credentials are updated or whenever the **reset_password**, **register_user**, **forgot_password**, or **update_user_details** widgets are used.

```python
with open('../config.yaml', 'w') as file:
    yaml.dump(config, file, default_flow_style=False)
```

<!--- ## 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/mkhorasani/Streamlit-Authenticator",
    "name": "streamlit-authenticator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "Python, Streamlit, Authentication, Components",
    "author": "Mohammad Khorasani",
    "author_email": "khorasani.mohammad@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/47/8c/73720cbba26a17bbda9b5118de19b460613322ed84fa01ce050be6caa35b/streamlit-authenticator-0.3.2.tar.gz",
    "platform": null,
    "description": "<img src=\"https://raw.githubusercontent.com/mkhorasani/Streamlit-Authenticator/main/graphics/logo.png\" alt=\"Streamlit Authenticator logo\" style=\"margin-top:50px;width:450px\"></img>\n<!--- [![Downloads](https://pepy.tech/badge/streamlit-authenticator)](https://pepy.tech/project/streamlit-authenticator) --->\n<!--- [![\"Buy Me A Coffee\"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/khorasani) --->\n\n**A secure authentication module to validate user credentials in a Streamlit application.**\n<br/><br/><br/>\n<a href=\"http://tinyurl.com/2p8mw32d\"><img src=\"https://raw.githubusercontent.com/mkhorasani/streamlit_authenticator_test/main/Web%20App%20Web%20Dev%20with%20Streamlit%20-%20Cover.png\" width=\"300\" height=\"450\">\n\n###### _To learn more please refer to my book [Web Application Development with Streamlit](http://tinyurl.com/2p8mw32d)._\n\n\n## Installation\n\nStreamlit-Authenticator is distributed via [PyPI](https://pypi.org/project/streamlit-authenticator/):\n\n```python\npip install streamlit-authenticator\n```\n\n## Example\n\nUsing Streamlit-Authenticator is as simple as importing the module and calling it to verify your predefined users' credentials.\n\n```python\nimport streamlit as st\nimport streamlit_authenticator as stauth\n```\n\n### 1. Creating a configuration file\n\n* Initially create a YAML configuration file and define your user's credentials: including names, usernames, and passwords (plain text passwords will be hashed automatically).\n* In addition, enter a name, random key, and number of days to expiry for a JWT cookie that will be stored on the client's browser to enable password-less re-authentication. If you do not require re-authentication, you may set the number of days to expiry to 0.\n* Finally, define a list of pre-authorized emails of users who can register and add their credentials to the configuration file with the use of the **register_user** widget.\n* **_Please remember to update the config file (as shown in step 9) after you use the reset_password, register_user, forgot_password, or update_user_details widgets._**\n\n```python\ncredentials:\n  usernames:\n    jsmith:\n      email: jsmith@gmail.com\n      failed_login_attempts: 0 # Will be managed automatically\n      logged_in: False # Will be managed automatically\n      name: John Smith\n      password: abc # Will be hashed automatically\n    rbriggs:\n      email: rbriggs@gmail.com\n      failed_login_attempts: 0 # Will be managed automatically\n      logged_in: False # Will be managed automatically\n      name: Rebecca Briggs\n      password: def # Will be hashed automatically\ncookie:\n  expiry_days: 30\n  key: some_signature_key # Must be string\n  name: some_cookie_name\npre-authorized:\n  emails:\n  - melsby@gmail.com\n```\n\n_Please note that the 'logged_in' field corresponding to each user's log-in status will be added automatically._\n\n### 2. Creating a login widget\n\n* Subsequently import the configuration file into your script and create an authentication object.\n\n```python\nimport yaml\nfrom yaml.loader import SafeLoader\n\nwith open('../config.yaml') as file:\n    config = yaml.load(file, Loader=SafeLoader)\n\nauthenticator = stauth.Authenticate(\n    config['credentials'],\n    config['cookie']['name'],\n    config['cookie']['key'],\n    config['cookie']['expiry_days'],\n    config['pre-authorized']\n)\n```\n\n> ### Authenticate\n> #### Parameters:\n>  - **credentials:** _dict_\n>    - Provides the usernames, names, passwords, and emails, and other user data.\n>  - **cookie_name:** _str_\n>    - Specifies the name of the JWT cookie stored on the client's browser for password-less re-authentication.\n>  - **cookie_key:** _str_\n>    - Specifies the key that will be used to hash the signature of the re-authentication cookie.\n>  - **cookie_expiry_days:** _float, default 30.0_\n>    - Specifies the number of days before the re-authentication cookie automatically expires on the client's browser.\n>  - **pre-authorized:** _list, default None_\n>    - Provides the list of emails of unregistered users who are authorized to register.\n>  - **validator:** _object, default None_\n>    - Provides a validator object that will check the validity of the username, name, and email fields.\n\n* Then render the login module as follows.\n\n```python\nauthenticator.login()\n```\n\n> ### Authenticate.login\n> #### Parameters:\n>  - **location:** _str, {'main', 'sidebar'}, default 'main'_\n>    - Specifies the location of the login widget.\n>  - **max_concurrent_users:** _int, default None_\n>    - Limits the number of concurrent users. If not specified there will be no limit to the number of users.\n>  - **max_login_attempts:** _int, default None_\n>    - Limits the number of failed login attempts. If not specified there will be no limit to the number of failed login attempts.\n>  - **fields:** _dict, default {'Form name':'Login', 'Username':'Username', 'Password':'Password', 'Login':'Login'}_\n>    - Customizes the text of headers, buttons and other fields.\n>  - **clear_on_submit:** _bool, default False_\n>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.\n> #### Returns:\n> - _str_\n>   - Name of the authenticated user.\n> - _bool_\n>   - Status of authentication, None: no credentials entered, False: incorrect credentials, True: correct credentials.\n> - _str_\n>   - Username of the authenticated user.\n\n![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/login_form.JPG)\n\n### 3. Authenticating users\n\n* You can then retrieve the name, authentication status, and username from Streamlit's session state using **st.session_state[\"name\"]**, **st.session_state[\"authentication_status\"]**, and **st.session_state[\"username\"]** to allow a verified user to proceed to any restricted content.\n* You may also render a logout button, or may choose not to render the button if you only need to implement the logout logic programmatically.\n* The optional **key** parameter for the logout button should be used with multi-page applications to prevent Streamlit from throwing duplicate key errors.\n\n```python\nif st.session_state[\"authentication_status\"]:\n    authenticator.logout()\n    st.write(f'Welcome *{st.session_state[\"name\"]}*')\n    st.title('Some content')\nelif st.session_state[\"authentication_status\"] is False:\n    st.error('Username/password is incorrect')\nelif st.session_state[\"authentication_status\"] is None:\n    st.warning('Please enter your username and password')\n```\n\n> ### Authenticate.logout\n> #### Parameters:\n>  - **button_name:** _str, default 'Logout'_\n>    - Customizes the button name.\n>  - **location:** _str, {'main', 'sidebar','unrendered'}, default 'main'_\n>    - Specifies the location of the logout button. If 'unrendered' is passed, the logout logic will be executed without rendering the button.\n>  - **key:** _str, default None_\n>    - Unique key that should be used in multi-page applications.\n\n![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/logged_in.JPG)\n\n* Or prompt an unverified user to enter a correct username and password.\n\n![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/incorrect_login.JPG)\n\n* You may also retrieve the number of failed login attempts a user has made by accessing **st.session_state['failed_login_attempts']** which returns a dictionary with the username as key and the number of failed attempts as the value.\n\n### 4. Creating a reset password widget\n\n* You may use the **reset_password** widget to allow a logged in user to modify their password as shown below.\n\n```python\nif st.session_state[\"authentication_status\"]:\n    try:\n        if authenticator.reset_password(st.session_state[\"username\"]):\n            st.success('Password modified successfully')\n    except Exception as e:\n        st.error(e)\n```\n\n> ### Authenticate.reset_password\n> #### Parameters:\n>  - **username:** _str_\n>    - Specifies the username of the user to reset the password for.\n>  - **location:** _str, {'main', 'sidebar'}, default 'main'_\n>    - Specifies the location of the reset password widget.\n>  - **fields:** _dict, default {'Form name':'Reset password', 'Current password':'Current password', 'New password':'New password', 'Repeat password': 'Repeat password', 'Reset':'Reset'}_\n>    - Customizes the text of headers, buttons and other fields.\n>  - **clear_on_submit:** _bool, default False_\n>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.\n> #### Returns::\n> - _bool_\n>   - Status of resetting the password.\n\n![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/reset_password.JPG)\n\n_Please remember to update the config file (as shown in step 9) after you use this widget._\n\n### 5. Creating a new user registration widget\n\n* You may use the **register_user** widget to allow a user to sign up to your application as shown below. If you require the user to be pre-authorized, set the **pre-authorization** argument to True and add their email to the **pre-authorized** list in the configuration file. Once they have registered, their email will be automatically removed from the **pre-authorized** list in the configuration file. Alternatively, to allow anyone to sign up, set the **pre-authorization** argument to False.\n\n```python\ntry:\n    email_of_registered_user, username_of_registered_user, name_of_registered_user = authenticator.register_user(pre_authorization=False)\n    if email_of_registered_user:\n        st.success('User registered successfully')\nexcept Exception as e:\n    st.error(e)\n```\n\n> ### Authenticate.register_user\n> #### Parameters:\n>  - **location:** _str, {'main', 'sidebar'}, default 'main'_\n>    - Specifies the location of the register user widget.\n>  - **pre-authorization:** _bool, default True_\n>    - Specifies the pre-authorization requirement, True: user must be pre-authorized to register, False: any user can register.\n>  - **domains:** _list, default None_\n>    - Specifies the required list of domains a new email must belong to i.e. ['gmail.com', 'yahoo.com'], list: the required list of domains, None: any domain is allowed.\n>  - **fields:** _dict, default {'Form name':'Register user', 'Email':'Email', 'Username':'Username', 'Password':'Password', 'Repeat password':'Repeat password', 'Register':'Register'}_\n>    - Customizes the text of headers, buttons and other fields.\n>  - **clear_on_submit:** _bool, default False_\n>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.\n> #### Returns:\n> - _str_\n>   - Email associated with the new user.\n> - _str_\n>   - Username associated with the new user.\n> - _str_\n>   - Name associated with the new user.\n\n![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/register_user.JPG)\n\n_Please remember to update the config file (as shown in step 9) after you use this widget._\n\n### 6. Creating a forgot password widget\n\n* You may use the **forgot_password** widget to allow a user to generate a new random password. This password will be automatically hashed and saved in the configuration file. The widget will return the username, email, and new random password which the developer should then transfer to the user securely.\n\n```python\ntry:\n    username_of_forgotten_password, email_of_forgotten_password, new_random_password = authenticator.forgot_password()\n    if username_of_forgotten_password:\n        st.success('New password to be sent securely')\n        # The developer should securely transfer the new password to the user.\n    elif username_of_forgotten_password == False:\n        st.error('Username not found')\nexcept Exception as e:\n    st.error(e)\n```\n\n> ### Authenticate.forgot_password\n> #### Parameters\n>  - **location:** _str, {'main', 'sidebar'}, default 'main'_\n>    - Specifies the location of the forgot password widget.\n>  - **fields:** _dict, default {'Form name':'Forgot password', 'Username':'Username', 'Submit':'Submit'}_\n>    - Customizes the text of headers, buttons and other fields.\n>  - **clear_on_submit:** _bool, default False_\n>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.\n> #### Returns:\n> - _str_\n>   - Username associated with the forgotten password.\n> - _str_\n>   - Email associated with the forgotten password.\n> - _str_\n>   - New plain text password that should be transferred to the user securely.\n\n![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/forgot_password.JPG)\n\n_Please remember to update the config file (as shown in step 9) after you use this widget._\n\n### 7. Creating a forgot username widget\n\n* You may use the **forgot_username** widget to allow a user to retrieve their forgotten username. The widget will return the username and email which the developer should then transfer to the user securely.\n\n```python\ntry:\n    username_of_forgotten_username, email_of_forgotten_username = authenticator.forgot_username()\n    if username_of_forgotten_username:\n        st.success('Username to be sent securely')\n        # The developer should securely transfer the username to the user.\n    elif username_of_forgotten_username == False:\n        st.error('Email not found')\nexcept Exception as e:\n    st.error(e)\n```\n\n> ### Authenticate.forgot_username\n> #### Parameters\n>  - **location:** _str, {'main', 'sidebar'}, default 'main'_\n>    - Specifies the location of the forgot username widget.\n>  - **fields:** _dict, default {'Form name':'Forgot username', 'Email':'Email', 'Submit':'Submit'}_\n>    - Customizes the text of headers, buttons and other fields.\n>  - **clear_on_submit:** _bool, default False_\n>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.\n> #### Returns:\n> - _str_\n>   - Forgotten username that should be transferred to the user securely.\n> - _str_\n>   - Email associated with the forgotten username.\n\n![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/forgot_username.JPG)\n\n### 8. Creating an update user details widget\n\n* You may use the **update_user_details** widget to allow a logged in user to update their name and/or email. The widget will automatically save the updated details in both the configuration file and re-authentication cookie.\n\n```python\nif st.session_state[\"authentication_status\"]:\n    try:\n        if authenticator.update_user_details(st.session_state[\"username\"]):\n            st.success('Entries updated successfully')\n    except Exception as e:\n        st.error(e)\n```\n\n> ### Authenticate.update_user_details\n> #### Parameters\n>  - **username:** _str_\n>    - Specifies the username of the user to update user details for.\n>  - **location:** _str, {'main', 'sidebar'}, default 'main'_\n>    - Specifies the location of the update user details widget.\n>  - **fields:** _dict, default {'Form name':'Update user details', 'Field':'Field', 'Name':'Name', 'Email':'Email', 'New value':'New value', 'Update':'Update'}_\n>    - Customizes the text of headers, buttons and other fields.\n>  - **clear_on_submit:** _bool, default False_\n>    - Specifies the clear on submit setting, True: clears inputs on submit, False: keeps inputs on submit.\n> #### Returns:\n> - _bool_\n>   - Status of updating the user details.\n\n![](https://github.com/mkhorasani/Streamlit-Authenticator/blob/main/graphics/update_user_details.JPG)\n\n_Please remember to update the config file (as shown in step 9) after you use this widget._\n\n### 9. Updating the configuration file\n\n* Please ensure that the configuration file is re-saved anytime the credentials are updated or whenever the **reset_password**, **register_user**, **forgot_password**, or **update_user_details** widgets are used.\n\n```python\nwith open('../config.yaml', 'w') as file:\n    yaml.dump(config, file, default_flow_style=False)\n```\n\n<!--- ## Credits\n- Mohamed Abdou for the highly versatile cookie manager in [Extra-Streamlit-Components](https://github.com/Mohamed-512/Extra-Streamlit-Components). --->\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A secure authentication module to validate user credentials in a Streamlit application.",
    "version": "0.3.2",
    "project_urls": {
        "Homepage": "https://github.com/mkhorasani/Streamlit-Authenticator"
    },
    "split_keywords": [
        "python",
        " streamlit",
        " authentication",
        " components"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4229c75f245f4343c526bd97f2bc65c05faccc90e4c95032645eff1d988fe872",
                "md5": "5f0c19be20a1584d4baf4eb2e9377d1e",
                "sha256": "0620768d01aa6c7bff4200f062effff333a8e0cfde9b5300a67ba878c51b0adc"
            },
            "downloads": -1,
            "filename": "streamlit_authenticator-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f0c19be20a1584d4baf4eb2e9377d1e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 22336,
            "upload_time": "2024-03-26T19:27:37",
            "upload_time_iso_8601": "2024-03-26T19:27:37.314285Z",
            "url": "https://files.pythonhosted.org/packages/42/29/c75f245f4343c526bd97f2bc65c05faccc90e4c95032645eff1d988fe872/streamlit_authenticator-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "478c73720cbba26a17bbda9b5118de19b460613322ed84fa01ce050be6caa35b",
                "md5": "624233415ef9faea25e866607d9ccf04",
                "sha256": "f17a77d0394a45d6554a72d890cc270d9be5328eeb12958898bf0183e7321ed6"
            },
            "downloads": -1,
            "filename": "streamlit-authenticator-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "624233415ef9faea25e866607d9ccf04",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 18754,
            "upload_time": "2024-03-26T19:27:42",
            "upload_time_iso_8601": "2024-03-26T19:27:42.809604Z",
            "url": "https://files.pythonhosted.org/packages/47/8c/73720cbba26a17bbda9b5118de19b460613322ed84fa01ce050be6caa35b/streamlit-authenticator-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-26 19:27:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mkhorasani",
    "github_project": "Streamlit-Authenticator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "streamlit-authenticator"
}
        
Elapsed time: 0.20587s