Debugging User Authentication Issues in CyberPanel
CyberPanel is a robust web hosting control panel; however, like any complex system, it may occasionally experience authentication issues. This guide offers a step-by-step approach to diagnosing and resolving user login problems in CyberPanel.
Initial Symptoms
Our troubleshooting process began with two primary symptoms:
- An error message indicating “Administrator matching query does not exist.”
- This error evolved into a “wrong password” message, despite the password being accurate.
Step 1: Verifying Database Connection and User Existence
To start, confirm that the database connection is functioning correctly and that the user exists within the system. Execute the following command in the terminal:
python python manage.py shell
Then, run the following Python code:
from django.contrib.auth.models import User
from django.contrib.auth.hashers import check_password
user = User.objects.get(username=’admin’)
print(check_password(‘your_password_here’, user.password))
If this returns True, it confirms that the user exists and the password is correctly stored in the database.
Step 2: Checking Database Connection
Next, verify that the database connection is operational:
from django.db import connection
cursor = connection.cursor()
cursor.execute(“SELECT 1”)
print(cursor.fetchone())
This should output (1,). If it does not, there may be a database connection issue that requires further investigation.
Step 3: Reviewing settings.py
It is essential to check the settings.py file for accurate database and authentication configurations. The relevant section should resemble the following:
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.mysql’,
‘NAME’: ‘cyberpanel’,
‘USER’: ‘cyberpanel’,
‘PASSWORD’: ‘your_password_here’,
‘HOST’: ‘localhost’,
‘PORT’: ”,
}
}
AUTHENTICATION_BACKENDS = [
‘django.contrib.auth.backends.ModelBackend’,
]
The file is located at:
/usr/local/CyberCP/CyberCP/settings.py
Ensure that these settings are correct and that the database password matches your actual database password.
Step 4: Verifying Authentication Backend
In the Django shell, check the authentication backends with the following command:
from django.conf import settings
print(settings.AUTHENTICATION_BACKENDS)
To execute this command, navigate to the CyberPanel directory:
/usr/local/CyberCP/
Then run:
python manage.py shell
This should return [‘django.contrib.auth.backends.ModelBackend’].
Step 5: Testing Authentication
Attempt to authenticate manually in the Django shell:
from django.contrib.auth import authenticate
user = authenticate(username=’admin’, password=’your_password_here’)
print(user)
If this returns the user object, it indicates that Django’s authentication system is functioning correctly.
Step 6: Checking User Model
Verify that CyberPanel is utilizing the default Django User model:
from django.conf import settings
print(settings.AUTH_USER_MODEL)
This should return ‘auth.User’.
Step 7: Database Integrity Check
Ensure that there is only one ‘admin’ user in the database. The following command should return 1:
User.objects.filter(username=’admin’).count()
Step 8: Debugging CyberPanel’s Login Process
If all previous checks pass yet you are still unable to log in, the issue may reside within CyberPanel’s custom login process. Consider investigating the following areas:
- Review the login view in the views.py files located within the CyberPanel directory structure.
- Look for any custom authentication code in files such as auth.py.
- Inspect any signals.py files for signal handlers that may be intercepting the login process.
To add debug logging to the login process, include the following code:
import logging
logger = logging.getLogger(name)
In the login function
logger.debug(f”Login attempt for user: {username}”)
logger.debug(f”Password check result: {check_password(password, user.password)}”)
Step 9: Checking for Missing Modules
If you encounter a ModuleNotFoundError, such as:
ModuleNotFoundError: No module named ‘firewall.models’
This indicates a missing or incorrectly configured module. To resolve this issue:
- Verify that the module directory exists:
ls /usr/local/CyberCP/firewall
- Ensure the module is included in INSTALLED_APPS within settings.py.
- Run Django migrations with the following commands:
python manage.py makemigrations
python /usr/local/CyberCP/manage.py migrate
Step 10: User Creation in CyberPanel
If you continue to experience issues, you may need to recreate the admin user. CyberPanel provides a custom command for this purpose, which is more comprehensive than Django’s default createsuperuser command.
The CyberPanel user creation command is defined in the /usr/bin/cyberpanel script. Here is how to use it:
cyberpanel createUser –firstName Cyber –lastName Panel –email [email protected] –userName admin –password securepassword –websitesLimit 0 –selectedACL admin –securityLevel HIGH
This command utilizes CyberPanel’s custom user creation logic, ensuring that the user is properly set up within CyberPanel’s ecosystem, including the correct ACL and security level.
Please note that it is a good idea after each of the above commands to restart the Cyberpanel service:
lscpd.service – LSCPD Daemon
-> systemctl restart lscpd