Create app without github

I am creating a demo authentication app with two fields username and password. It will look up username and password from a configuration file that has a list will display that the user is authenticated if these two fields match with an entry.

Is there any other way to create an app other than from github? I don’t want to put credentials in the repo.

Alternatively is there a better way to put the configuration file somewhere else where I can keep adding more users to configuration file and the streamlit app communicates via an API or other method

Hi @Avis,

Thanks for sharing your question with the community! :balloon: Please update your debugging post to include a code snippet and a link to your app’s public GitHub repo – this will allow the community to help you find an answer as quickly as possible. In the meantime, this post will be tagged as needs-more-info.

Hi @tonykip

I put it up as a discussion not debugging, but anyways here is the code below if it helps in getting suggestions

import streamlit as st
import configparser

def read_config(filename='config.ini'):
    config = configparser.ConfigParser()
    config.read(filename)
    return config

def authenticate(username, password, config):
    users = config['Users']
    if username in users and users[username] == password:
        return True
    return False

def main():
    st.sidebar.title('Login')
    username = st.sidebar.text_input('Username')
    password = st.sidebar.text_input('Password', type='password')

    if st.sidebar.button('Login'):
        config = read_config()
        if authenticate(username, password, config):
            st.sidebar.success('Login successful')
            st.session_state['authenticated'] = True
        else:
            st.sidebar.error('Invalid username or password')

    if st.session_state.get('authenticated'):
        st.title('Authenticated Section')
        text = st.text_input('Enter Text')
        if st.button('Display Text'):
            st.write('Entered text:', text)

if __name__ == '__main__':
    main()

The config.ini file contents is something like below

[Users]
user1 = password1
user2 = password2

I don’t want to put the config.ini on gihub. Is there a way to directly upload to streamlit cloud. Also I will be adding more to the list so is there a convenient way to do that?

1 Like

You can save your credentials in the secret file.

I use deta space.

But you can use other ways such as saving it to google drive, or saving the config to google sheet and use the sheet to authenticate the user. Or Firestore database. or use from data sources.

In case you don’t know, there is also a lib that can handle authentication. It supports a cookie to recover user login status in case a user reloads a page or re-login (after exiting the page) without inputting credentials again as long as the user has not logout.

2 Likes

:heavy_plus_sign: 1 on @ferdy’s solution of using the auth and saving it to secrets. Many ways to handle this.

1 Like

@Avis, thanks for adding the context with code.

@fredy Thanks for the suggestion, I was able to come up with a solution using secret file and google sheets. I will try to come up with a better way of authentication using Streamlit-Authenticator later on

1 Like

Feel free to share your learnings here once you build it out and test it.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.