Laravel 5 Auth: These credentials do not match our records
When migrating from Laravel 4 to version 5, the most noticeable shift is often how authentication is handled out of the box. In L4, you typically built custom controllers and models to manage users. Laravel 5, however, introduces a robust built-in authentication scaffolding via Auth::routes(). While this saves development time by generating standard registration and login views/controllers automatically, it can lead to confusion when switching between environments or sessions.
The specific error message you are encounteringâ"These credentials do not match our records"âis the default response returned by Laravel's Auth::attempt() method when it fails to validate a user. In your scenario, the system successfully registers new users and logs them in automatically upon signing up. This behavior suggests that the registration logic is functioning as intended, likely because the default controller handles both database insertion and session creation in one go. However, once you log out and attempt to return manually, the validation fails.
This discrepancy usually points to a mismatch between the data stored in your database and the credentials provided during the login attempt. In Laravel 5, the built-in authentication system relies on a specific hash algorithm configured in your config/auth.php file. By default, this is set to bcrypt. If you are testing locally and have previously run migrations or seeded a database with users using a different hashing method (such as the MD5 or SHA1 often found in older Laravel 4 tutorials), the password verification will fail even if the username and password strings match exactly.
To resolve this, verify your config/auth.php file to ensure the default hash driver is set to bcrypt. If you are using a fresh install of L5, the database should be seeded with users hashed correctly by default. However, a common pitfall occurs when developers manually insert a user into the database or copy-paste passwords from an external list without hashing them first. The password field in your users table must contain a hash, not a plain text string.
You can inspect this by running a simple query via Artisan Tinker:
php artisan tinker
>>> $user = App\User::first();
>>> var_dump(password_verify($user->password, 'your_plaintext_password'));
If the password you are using to log in does not match the hash stored in the database, Auth::attempt will return false, triggering the "credentials do not match" error. Ensure that your registration form is actually saving the hashed password and not storing the raw input. The default scaffolding handles this correctly via Hash::make().
Another potential issue arises if you have customized the login controller or route definition. The built-in AuthController expects specific fields in the POST request: email and password. If your view form submits these fields with different names (e.g., user_email instead of email), the validator will reject them before hashing occurs. Check your login Blade template to ensure the input names match the model attributes exactly.
If you are migrating from Laravel 4, you might also be running into an issue where the session state is being cleared unexpectedly between the registration flow and the manual login attempt. While this usually manifests as a "not logged in" error rather than a credentials mismatch, it can sometimes feel like the system doesn't recognize your identity. Ensure that session_start() isn't being manually called elsewhere in your application, which could cause conflicts with Laravel's session driver handling.
If you find yourself needing to customize the authentication flow significantly beyond what Auth::routes() provides, you may eventually need to write a custom controller. However, for standard use cases, debugging the hash configuration and input field names should resolve the issue without reinventing the wheel. For more complex authentication requirements or if you need to integrate external identity providers, LaravelCompany offers resources on extending the default auth system with third-party packages that handle these edge cases seamlessly.