Overview
NapCat supports multiple login methods for QQ accounts. This guide covers QR code scanning, password login, and quick login with practical code examples from the framework.Login Flow
The login process is managed by theNodeIKernelLoginListener which handles various login events:
The login system is implemented in
napcat.ts:92-160 and provides callback-based event handling for all login methods.QR Code Login
QR code login is the most secure and commonly used method.Basic QR Code Flow
1
Initialize Login Service
The login service connects automatically when NapCat starts:
2
Receive QR Code
When the QR code is generated, the The
onQRCodeGetPicture event fires:qrcodeUrl is a data URL that can be displayed directly in the WebUI.3
User Scans QR Code
When a user scans the QR code with their phone:
4
Login Success
After the user confirms on their phone:
Handle QR Code Expiration
QR codes expire after a certain time:Refresh QR Code
Implement QR code refresh functionality:Password Login
Password login requires MD5-hashed password and may need additional verification.Basic Password Login
1
Prepare Login Data
2
Execute Password Login
From
napcat.ts:244-276:Handle CAPTCHA Verification
If Tencent requires CAPTCHA verification:CAPTCHA Login (Step 2)
After user completes CAPTCHA:New Device Verification
For new or unusual devices:New Device Login (Step 3)
Quick Login
Quick login allows re-authentication with previously logged-in accounts.Get Login List
Retrieve the list of accounts that support quick login:Execute Quick Login
Fromnapcat.ts:211-235:
Handle Login Failures
Implement comprehensive error handling:Check Existing Login
Prevent duplicate logins:Complete Login Example
Best Practices
- Prefer QR Code Login: Most secure and requires no password handling
- Hash Passwords: Always use MD5-hashed passwords, never plain text
- Handle All Error Cases: Implement handlers for CAPTCHA and device verification
- Timeout Management: Set appropriate timeouts for login operations
- State Management: Track login state to prevent duplicate attempts
Next Steps
Message Handling
Learn how to send and receive messages
Deployment
Deploy NapCat in production
