Laravel 5.2 login always throws "These credentials do not match our records."

I am trying to implement authentication using Laravel 5.2. I do this watch, but I always get "These credentials do not match our records." when trying to log in.

I tried messing around with the routes, adjusted the size of the column in the user table, tried the user login, etc. I just can't get it to work.

Here's how I made a table of my users using migration:

Notes:

  • I need to use raw instructions for a school project.
  • Laravel suggests password fields should be 60 characters (already tried already 100)
  • Laravel requires 100 char columns for remember_token
  • Edit: The database and user table were created successfully, and user data is saved during registration.

the code:

    DB::statement("CREATE TABLE users(
      id INT PRIMARY KEY AUTO_INCREMENT,
      firstname VARCHAR(50) NOT NULL,
      lastname VARCHAR(50) NOT NULL,
      password VARCHAR(60) NOT NULL,
      email VARCHAR(255) UNIQUE NOT NULL,
      bio VARCHAR(500),
      gender ENUM('F','M') NOT NULL,
      birthday DATE NOT NULL,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
      updated_at TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      level INT DEFAULT 0,
      remember_token VARCHAR(100)
    )");

Here is my login form:

<form method="POST" action="login">
{!! csrf_field() !!}
<table>
  <tr>
    <td> <label for="email">E-mail: </label>  </td>
    <td>  <input type="email" name="email" value="{{ old('email') }}">  </td>
  </tr>
  <tr>
    <td> <label for="password">Password: </label>  </td>
    <td> <input type="password" name="password" id="password">  </td>
  </tr>
  <tr>
    <td> <label for="remember">Remember me: </label>  </td>
    <td> <input type="checkbox" name="remember">  </td>
  </tr>
</table>
<div>
    <button type="submit">Login</button>
</div>
</form>

My routes:

Route::group(['middleware' => ['web']], function () {
  Route::get('registration', 'MainController@getRegister');
  Route::get('login', 'MainController@getLogin');
  Route::get('logout', 'Auth\AuthController@logout');
  Route::post('registration', 'Auth\AuthController@postRegister');
  Route::post('login', 'Auth\AuthController@postLogin');
});

Route::group(['middleware' => ['auth','web']], function () {
  Route::get('/', 'MainController@getIndex');
});

AuthController class:

class AuthController extends Controller
{
    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Where to redirect users after login / registration.
     *
     * @var string
     */
     protected $redirectTo = '/';
     protected $loginPath = 'login';

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('web', ['except' => 'logout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'firstname' => 'required|max:50',
            'lastname' => 'required|max:50',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
            'birthday' => 'required',
            'gender' => 'required'
        ]);
    }



    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'firstname' => $data['firstname'],
            'lastname' => $data['lastname'],
            'birthday' => $data['birthday'],
            'gender' => $data['gender'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

    protected function logout(){
      if (Auth::check()){
        Auth::logout();
      }
      return redirect('login');
    }
}
+4
source share
1 answer

After the mess, I realized for a while that he needed to do something with the database. Of course, after some testing, I realized that the email and password columns should look like this:

 password CHAR(60) NOT NULL,
 email VARCHAR(255) character set utf8 collate utf8_bin not null

My hunch is that the password column was a problem and that Laravel string comparison performs poorly with VARCHAR password columns.

+5
source

All Articles