How to Set user name and Password of phpmyadmin

How to Set user name and Password of phpmyadmin

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Enabling Authentication in phpMyAdmin

By default, modern versions of phpMyAdmin come with authentication disabled to ensure a smooth user experience during local development. This is convenient for quick iterations but presents a significant security risk if your server is ever exposed to the internet or accessed from an untrusted network. If you are running XAMPP on localhost and see the dashboard load immediately without prompting for credentials, it is because the $enableAuth configuration directive has been left at its default setting or explicitly disabled in your config.inc.php.

To enforce a username and password requirement when accessing localhost/phpmyadmin, you must modify the core configuration file. Open config.inc.php located typically within the phpMyAdmin directory of your XAMPP installation. Look for the line defining $enableAuth. If it is set to false or commented out, change it to:

$enableAuth = true;

Once this flag is enabled, phpMyAdmin will check for credentials before loading the interface. However, enabling authentication alone does not automatically create a user account; you must also define the specific username and password in that same file. Search for the $iDefaultUser and $iDefaultPassword variables. You can set these directly in the config file, though this method stores passwords in plain text within the configuration script, which is generally discouraged for production environments but acceptable for isolated localhost setups.

$iDefaultUser = 'root';
$iDefaultPassword = 'your_secure_password_here';

Alternatively, you can rely on the default MySQL user credentials often used with XAMPP (root with no password or a specific root password) if you prefer not to hardcode values in the config file. Be aware that simply enabling authentication might lock you out if you have forgotten the password and cannot access the database server directly via CLI tools like mysql.exe. Always ensure you can still connect to MySQL from the terminal before saving changes to config.inc.php.

A critical consideration when implementing this change is how it interacts with other security settings. Enabling authentication does not automatically encrypt your passwords or protect against SQL injection; those protections must be implemented separately. If you are deploying phpMyAdmin in a production environment, hardcoding credentials in config.inc.php is a poor practice because the file is often committed to version control or stored in web-accessible directories. Instead, use environment variables or server-level configuration to manage secrets securely.

Another potential pitfall involves the caching layer. If you have enabled session storage or are using a reverse proxy, phpMyAdmin might still behave unexpectedly if the session cookie settings do not align with your authentication flow. Ensure that $cfg['PmaAbsoluteUri'] is correctly set if you are accessing the application via a subdomain or a different path structure than the default localhost/phpmyadmin.

If you require more granular control over user permissions, phpMyAdmin offers a built-in user management system that can be configured in the config file. This allows you to create multiple users with specific privileges rather than relying solely on the MySQL root account. You can define arrays of users and assign them to specific hostnames or IP ranges.

$cfg['Servers'][$i]['auth_type'] = 'config'; // Or 'cookie' for session-based auth
$cfg['Servers'][$i]['user'] = 'admin_user';
$cfg['Servers'][$i]['password'] = hash('sha256', 'your_encrypted_password');

Using hash() to store passwords prevents storing them in plain text, though you must ensure the hashing algorithm matches how phpMyAdmin validates credentials. If you opt for auth_type set to cookie, the password is hashed and stored in a session cookie rather than the config file, offering better security at the cost of slightly more complexity in setup.

For developers using Laravel or similar frameworks alongside XAMPP, ensure that your application does not attempt to handle database connections through phpMyAdmin's UI while also managing them via your framework's configuration. Mixing authentication methods can lead to session conflicts or unexpected redirect loops. Always keep the config.inc.php file outside of public web directories if possible, or restrict access strictly to localhost IPs to mitigate exposure risks.

Finally, remember that enabling authentication changes the entry point behavior significantly. Users will now see a login form immediately upon accessing the URL. If you intend to share this setup with others, ensure they know the credentials and that the configuration file has been backed up before testing.

Our network