How do1e/njulogin works
Project Overview and Purpose
• NJUlogin is a Python library providing unified authentication for 南京大学 (NJU) services. It supports three main login methods: QR (扫码) login, password-based login, and cookie loading.
• The library interacts with NJU’s authentication servers and provides a layer on top of the HTTP request mechanism (via its own get/post methods) to maintain session information.
• The README and file structure confirm that it is a standalone authentication module (rather than a full-stack web application or compiler). Its primary goal is to handle different login flows and integrate a captcha recognition component.
Analyzing the File Structure
• Top-level direct items include configuration files (.gitignore, LICENSE, requirements.txt, etc.) and directories like NJUlogin (the package), demos (usage examples), and test.
• Within the NJUlogin package, there are three key areas:
• Login Strategy Modules:
▪ QRlogin.py – Implements QR code-based login.
▪ pwdLogin.py – Implements login based on username and password.
▪ base.py – Likely serves as the shared base layer for login sessions (including cookies export/load).
• Captcha OCR Module:
▪ Located in NJUlogin/captchaOCR; it includes scripts and an ONNX model (common.onnx) to handle captcha recognition. Files such as ocr.py, charsets.py, and utils.py assist in extracting the captcha text.
• Utility Components:
▪ Located in NJUlogin/utils; these provide various helper functionalities like configuration management (config.py), URL processing (urls.py), and request-related operations (get_post.py).
Architectural Components and Their Relationships
• Core Login Process:
• The main authentication process is built around creating a session that interacts with external authentication servers.
• The base component and exported login objects (from QRlogin, pwdLogin, etc.) wrap around the Python requests library to handle HTTP GET/POST calls.
• Login Strategies:
• QRlogin: Handles the generation, display (both printed QR code and saved image backup), and validation of the QR code.
• pwdLogin: Uses user-provided credentials to authenticate through the web gateway.
• Base login (and its cookie export/load functionality) provides a foundation that underpins both strategies.
• Captcha Recognition:
• The captchaOCR module is plugged into the login sequences to handle any captcha requirements. It processes images/captchas via an ONNX model and performs OCR to ease the login process.
• Utilities:
• Utilities support auxiliary tasks needed by the above modules such as configuration loading, URL handling, and request preparation.
• External Interaction: