A user authentication system built with Streamlit, featuring image captcha verification, user registration, and login functionality.
- Image Captcha: Randomly generates 4-character captchas with interference lines and dots for enhanced security
- User Registration: Supports new user registration with encrypted password storage
- User Login: Validates username, password, and captcha
- Session Management: Displays welcome page after login with logout functionality
pylogin/
app.py # Main Streamlit application
captcha.py # Captcha generation module
user_manager.py # User management module
requirements.txt # Project dependencies
©À users.json # User data file (auto-generated)
README.md # This file
- Python 3.7+
- pip package manager
pip install -r requirements.txtOr install manually:
pip install streamlit Pillowstreamlit run app.pyAfter starting, application will display access URLs:
Local URL: http://localhost:8501
Network URL: http://your-ip:8501
- Open your browser and navigate to application URL
- Click on "Register" tab
- Fill in registration information:
- Username: Enter your desired username
- Password: Enter your password (minimum 6 characters)
- Confirm Password: Re-enter your password
- Captcha: Enter captcha shown in image (case-insensitive)
- Click "Register" button
- Upon successful registration, a success message will appear. Click "Go to Login" to proceed
- In "Login" tab, fill in your login information:
- Username: Enter your username
- Password: Enter your password
- Captcha: Enter captcha shown in image (case-insensitive)
- Click "Login" button
- Upon successful login, a welcome page will be displayed
- If captcha is unclear, click to "Refresh Captcha" button
- A new captcha will be generated; please enter to new captcha
- After logging in, click "Logout" button
- You will be redirected to login page
- Captcha: Captcha is case-insensitive but must be entered accurately
- Password Requirements: Password must be at least 6 characters long
- Username: Usernames must be unique; duplicate usernames will result in an error
- Data Storage: User data is stored in
users.jsonfile with SHA256 encrypted passwords - Session Management: Login state is maintained in browser sessions; page refresh does not lose login status
- Uses PIL (Pillow) library for image generation
- Randomly selects uppercase letters and numbers
- Adds interference lines and dots to prevent automated recognition
- Base64 encoded for embedding in web pages
- User data stored in JSON format
- Passwords encrypted using SHA256 hash algorithm
- Supports user registration and login validation
- Uses
st.session_statefor application state management - Captcha, login status, and other information stored in session
- Prevents state loss on page refresh
A: Please ensure:
- Captcha is entered correctly (case-insensitive)
- Captcha has not expired (if inactive for a long time, please refresh)
- Not using an old captcha after multiple "Refresh Captcha" clicks
A: Please check:
- Username and password are entered correctly
- Password case sensitivity
- Captcha is entered correctly
A: You can directly edit users.json file to remove corresponding user entry, or clear entire file to reset all users.
A: The current version does not support password modification. You need to delete user and re-register.
- Add new pages or functionality in
app.py - Add user management methods in
user_manager.py - Modify captcha generation logic in
captcha.py
You can modify to following configurations in app.py:
- Captcha length: Modify
lengthparameter inCaptchaGenerator - Captcha image size: Modify
widthandheightparameters - Minimum password length: Modify validation logic in registration form
This project is licensed under to Apache License 2.0 - see to LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
For questions or suggestions, please contact to developer.