timmy / 使用 Streamlit 建立簡單使用者驗證系統
0 curtidas
0 bifurcações
1 arquivos
Última atividade 10 months ago
這段程式碼使用 streamlit_authenticator 建立一個簡單的登入系統,支持使用者驗證(帳號、密碼)和登出功能,並在側邊欄提供登出按鈕。密碼經過雜湊處理以增加安全性。
| 1 | import streamlit as st # 匯入 streamlit 模組 |
| 2 | import streamlit_authenticator as stauth # 匯入 streamlit_authenticator 模組 |
| 3 | |
| 4 | names = ["John", "Mary"] # 定義名字清單 |
| 5 | usernames = ["john", "mary"] # 定義使用者名清單 |
| 6 | passwords = ["1234", "5678"] # 定義密碼清單 |
| 7 | |
| 8 | hashed_passwords = stauth.Hasher(passwords).generate() # 使用 Hasher 類別對密碼進行雜湊處理 |
| 9 | |
| 10 | authenticator = stauth.Authenticate( # 建立一個 stauth.Authenticate 的實例 authenticator |
Próximo
Anterior