Streamlit应用程序使用Streamlit-Authenticator进行用户的安全身份验证实践(解决升级问题)

news/2024/10/21 21:43:35/

在Streamlit官方文档中,没有提供提供安全身份验证组件。目前,第三方streamlit-authenticator提供此功能,详见引用我原来的博文,在《Streamlit应用程序使用Streamlit-Authenticator进行用户的安全身份验证实践》文中,原使用的代码报错:

authenticator = stauth.Authenticate(names, usernames, hashed_passwords,
TypeError: __init__() got multiple values for argument 'cookie_expiry_days'

报错原因是Streamlit-Authenticator包升级了,原代码发生了改变,解决办法如下:

import streamlit as st
import streamlit_authenticator as stauth
import PVForecastWeb# 此行代码被强制要求放在第一行。
st.set_page_config(layout="wide") #设置屏幕展开方式,宽屏模式布局更好credentials = {'usernames': {'xiaoyw': {'email': 'xiaoyw****@gmail.com','name': '肖永威','password': '*************'},   'admin': {'email': 'admin***@gmail.com','name': '管理员','password': '************  '} }}authenticator = stauth.Authenticate(credentials,'some_cookie_name', 'some_signature_key', cookie_expiry_days=30)name, authentication_status, username = authenticator.login('Login', 'main')if authentication_status:with st.container():cols1,cols2 = st.columns(2)cols1.write('欢迎 *%s*' % (name))with cols2.container():authenticator.logout('Logout', 'main')PVForecastWeb.main()  # 进入业务应用
elif authentication_status == False:st.error('Username/password is incorrect')
elif authentication_status == None:st.warning('Please enter your username and password')

其中,密码使用其提供的函数加密,输出字符串沾到代码中即可。

hashed_passwords = stauth.Hasher(['S0451', 'ad4516']).generate()

在这里插入图片描述

当然,可以使用其帮助https://github.com/mkhorasani/Streamlit-Authenticator/tree/main中的yaml配置文件,在此不再累述。

版本变化情况:

版本号时间说明
v0.2.2May 2023Added a unique key for the logout button to prevent duplicate key errors.
v0.2.1Jun 25, 2022
v0.1.5May 24, 2022Enhanced reauthentication cookie checking,Featured ability to import credentials and cookie setting

参考:
肖永威. Streamlit应用程序使用Streamlit-Authenticator进行用户的安全身份验证实践. CSDN博客. 2022.05


http://www.ppmy.cn/news/93114.html

相关文章

Java-API简析_java.lang.Package类(基于JDK1.8)(浅析源码)

【版权声明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) https://blog.csdn.net/m0_69908381/article/details/130806567 出自【进步*于辰的博客】 其实我的【Java-API】专栏内的博文对大家来说意义是不大的。…

RHCE 第五次作业

1.总结变量的类型及含义? 变量类型: 1,自定义变量: 在当前的shell命令行界面设置的变量是局部变量 例: num1 namezhangsan 含义:仅在当前shell生效. 2,环境变量: 全局变量,通过export 导出后的局部变量是全局变量 例: …

“Shell“SNAT,DNAT

文章目录 一.SNAT1.1 SNAT原理1.2 SNAT的应用环境1.3 SNAT工作原理1.4 进行SNAT转换后1.5 配置SNAT策略1.6SNAT实验 二.DNAT2.1 DNAT工作原理2.2 配置DNAT策略2.3 DNAT实验 一.SNAT 1.1 SNAT原理 SNAT原理:修改数据包的源地址。SNAT 应用环境:局域网主…

探讨一次订单拆单流程

欢迎大家关注公众号「JAVA前线」查看更多精彩分享文章,主要包括源码分析、实际应用、架构思维、职场分享、产品思考等等,同时欢迎大家加我微信「java_front」一起交流学习 1 文章概述 消费者在购物时,电商平台会生成订单。订单相当于是购物者…

本地提权漏洞分析【网络安全】

0. 前言 CVE-2023-21752 是 2023 年开年微软第一个有 exploit 的漏洞,原本以为有利用代码会很好分析,但是结果花费了很长时间,难点主要了两个:漏洞点定位和漏洞利用代码分析,欢迎指正。 1. 漏洞简介 根据官方信息&a…

5月份月刊总结

5月份月刊总结 目录概述需求: 设计思路实现思路分析1.技术经理 参考资料和推荐阅读 Survive by day and develop by night. talk for import biz , show your perfect code,full busy,skip hardness,make a better result,wait for change,challenge Sur…

使用ScreenToGif录制GIF动态图

文章目录 1.下载ScreenToGif工具2. 下载后双击下面的.msi文件进行安装3. 在编辑器中可以对所有帧添加文字描述 1.下载ScreenToGif工具 链接:https://pan.baidu.com/s/1rvFZSbMdNus90hbzxsJlGA 提取码:gyqe2. 下载后双击下面的.msi文件进行安装 按照默认…

imPlot的使用

1、概述 https://github.com/epezent/implot https://github.com/ocornut/imgui