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
Thanks for sharing your question with the community! 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.
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?
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.
@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