New Component: Streamlit-Authenticator, a secure authenticaton module to validate user credentials in a Streamlit application

Hey @xu2xulim, glad it’s helped! The cookie is saved as a JWT (JSON web token) where the integrity of its contents is verified using a hashed signature. Therefore, I’m inclined to say that there is no need to hide the cookie name since even if someone comes across the cookie itself, they will not be able to tamper with its contents. However, if it does give you peace of mind, then by all means yes you can conceal it. The cookie’s key on the other hand must be kept private as it can be misused. You can read more about JWT’s here.

1 Like

Thanks for your effort. It helped me alot 
 I am wondering if there is a way to use this component with multi level authentication
 For example to allow admin to access all features while other users access to limited features
 thanks in advance

Hi @Afahim, glad it was useful. You can simply create a username called ‘admin’ or anything similar and give them advanced user privileges if they login, i.e. have an if statement to check if username == ‘admin’ and then render the content that only the admin should view. Regards.

1 Like

How do i add

  1. a signup page here
    1.1 Looking to add signup : append names = [‘x’] => [‘x’,‘y’]
    1.2 Append password : passwords = [‘1’] =>[‘1’,‘2’]

  2. Reset Password for a given user ?
    2.1 Reset password for a given user

Hi @naashonomics, I am working on an update for a user registration form that will be released in the near future, as soon as it’s ready I will update everyone on this channel. Cheers.

1 Like

how do we use st.session_state[“name”] in multipage streamlit application ? thanks in advance

You can retrieve it exactly the way you have written it - st.session_state[“name”], there is no restriction regarding multipage apps, you can access you session state variables in any page.

1 Like

@mkhorasani thank you very much for your great work, now since the official multipage apps from streamlit has been released, how can we use this streamlit authenticator for the official multipage apps? can you give an example, thank you

@streamlit4crypto2022 you’re most welcome. You can use streamlit-authenticator in the same way that you previously would use it. Invoke the login widget on your main page, then access the authentication_status variable through session state i.e. st.session_state[“authentication_status”] on all your other pages to authenticate your user on to each and every page. Session state is persistent across all pages.

Is there a way to not show the login screen for a couple of seconds, when the user is already logged and the app is refresh?

Hello, I’ve been looking forward to try this on, so I copy/paste the code to test it out, but when I tried to run it, the app kept reloading itself before I put the credentials, do you know how can I fix it?

Can you share your code please?

Will look into it.

Dear all, the latest version of Streamlit-Authenticator v0.2.1 has just been released with the following new features:

  1. Reset password widget
  2. Register new user widget
  3. Forgot password widget
  4. Forgot username widget
  5. Update user details widget

Aswell as a whole host of other minor updates.

Enjoy!

Hello @mkhorasani , I am facing an error TypeError: init() got multiple values for argument ‘cookie_expiry_days’

can anyone help me solve this

Please note that as of v0.2.1, the names, usernames, and passwords are passed as one combined dictionary to the Authenticate class. Please refer to the readme file for further instructions on what arguments to pass.

Hello,

I loaded the yam file, and then, made this:

authenticator = stauth.Authenticate(
config[‘credentials’],
config[‘cookie’][‘name’],
config[‘cookie’][‘key’],
config[‘cookie’][‘expiry_days’]),
config[‘preauthorized’]
)

name, authentication_status, username = authenticator.login(‘Login’, ‘main’)
if authentication_status:
st.write(f’Welcome {name}')
st.title(‘Some content’)
authenticator.logout(‘Logout’, ‘main’)

elif authentication_status == False:
st.error(‘Username/password is incorrect’)
elif authentication_status == None:
st.warning(‘Please enter your username and password’)

But, when I press the login button, nothing happens, just this:

could u help me, plz?

Dear Gabriel,

I’m not entirely sure what the problem may be, but can you please check that you are using the following versions of packages:

    "PyJWT >=2.3.0",
    "bcrypt >= 3.1.7",
    "PyYAML >= 5.3.1",
    "streamlit >= 0.86",
    "extra-streamlit-components >= 0.1.55"

Hi!

Yes, im using the same versions of packages!

Im trying to solve, but, with no success

I did have what looks like the same issue and it was due to having installed the jwt package instead of the pyjwt package (very easy to mix the two together, they also both import with import jwt). If this is the case you might see in the log a warning that says that jwt does not have decode method (or something similar, I do not remember the details).