Skip to content
/ pylogin Public

A user authentication system built with Streamlit, featuring image captcha verification, user registration, and login functionality.

License

Notifications You must be signed in to change notification settings

DSDTB/pylogin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyLogin - Streamlit Login System with Captcha

A user authentication system built with Streamlit, featuring image captcha verification, user registration, and login functionality.

Features

  • 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

Project Structure

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

Installation

Prerequisites

  • Python 3.7+
  • pip package manager

Install Dependencies

pip install -r requirements.txt

Or install manually:

pip install streamlit Pillow

Run Application

streamlit run app.py

After starting, application will display access URLs:

Local URL: http://localhost:8501
Network URL: http://your-ip:8501

Usage

User Registration

  1. Open your browser and navigate to application URL
  2. Click on "Register" tab
  3. 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)
  4. Click "Register" button
  5. Upon successful registration, a success message will appear. Click "Go to Login" to proceed

User Login

  1. In "Login" tab, fill in your login information:
    • Username: Enter your username
    • Password: Enter your password
    • Captcha: Enter captcha shown in image (case-insensitive)
  2. Click "Login" button
  3. Upon successful login, a welcome page will be displayed

Refresh Captcha

  • If captcha is unclear, click to "Refresh Captcha" button
  • A new captcha will be generated; please enter to new captcha

Logout

  • After logging in, click "Logout" button
  • You will be redirected to login page

Important Notes

  1. Captcha: Captcha is case-insensitive but must be entered accurately
  2. Password Requirements: Password must be at least 6 characters long
  3. Username: Usernames must be unique; duplicate usernames will result in an error
  4. Data Storage: User data is stored in users.json file with SHA256 encrypted passwords
  5. Session Management: Login state is maintained in browser sessions; page refresh does not lose login status

Technical Details

Captcha Generation

  • 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 Management

  • User data stored in JSON format
  • Passwords encrypted using SHA256 hash algorithm
  • Supports user registration and login validation

Streamlit Session

  • Uses st.session_state for application state management
  • Captcha, login status, and other information stored in session
  • Prevents state loss on page refresh

FAQ

Q: Captcha always shows as incorrect?

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

Q: Registration successful but cannot login?

A: Please check:

  • Username and password are entered correctly
  • Password case sensitivity
  • Captcha is entered correctly

Q: How to delete a user?

A: You can directly edit users.json file to remove corresponding user entry, or clear entire file to reset all users.

Q: How to change password?

A: The current version does not support password modification. You need to delete user and re-register.

Development

Adding New Features

  1. Add new pages or functionality in app.py
  2. Add user management methods in user_manager.py
  3. Modify captcha generation logic in captcha.py

Custom Configuration

You can modify to following configurations in app.py:

  • Captcha length: Modify length parameter in CaptchaGenerator
  • Captcha image size: Modify width and height parameters
  • Minimum password length: Modify validation logic in registration form

License

This project is licensed under to Apache License 2.0 - see to LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Contact

For questions or suggestions, please contact to developer.

About

A user authentication system built with Streamlit, featuring image captcha verification, user registration, and login functionality.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages