Auth::attempt($credentials) always returns false

前端 未结 3 1438
轮回少年
轮回少年 2021-01-22 06:23

Hi there I am new to laravel and I am trying to code functionality of my login form here are the codes:

this is how I create new user (works well)

public         


        
相关标签:
3条回答
  • 2021-01-22 06:56

    Check to make sure that your database password field is 60 characters.

    0 讨论(0)
  • 2021-01-22 07:15

    To all laravel 4 developers who are facing the Auth::attempt() login failure with valid creditials!

    Solution:

    • In app/config/app.php change type: 'cipher' => MCRYPT_RIJNDAEL_128 to 'cipher' => MCRYPT_RIJNDAEL_256 and re-hash all passwords
    • In Model add method:

       public function setPasswordAttribute($pass) {
      
           $this->attributes['password'] = Hash::make($pass);
       }
      
    • In UserController:

      //Create User or Register

         public function postCreate() {
      
          $input = Input::all();
          $user = new User;
          $user->username = Input::get('username');
          $user->email = Input::get('email');
          $user->password = Hash::make(Input::get('password'));    
          $user = User::create($input);
          return Redirect::action("Frontend\HomeController@index");
      

      }

      //Login or Sign in

      public function postSignin() {
      
          $userdata = array(
              'username' => Input::get('username'),
              'password' => Input::get('password')
          );
      
          if (Auth::attempt($userdata, true)) {
               Session::put('username', Auth::user()->username);
               return Redirect::action("Frontend\HomeController@index");
          } else {
               return Redirect::action("Frontend\UserController@getLogin")
                      ->with('message', 'Your username/password combination was incorrect')
                      ->withInput();
      }
      

    Hope i have helped someone out there

    0 讨论(0)
  • 2021-01-22 07:16

    Fool me! Although I have checked it many times, I could not see the line 'username' => 'email', in auth config file.

    it should be 'username' => 'username', since I am going to use username for login.

    0 讨论(0)
提交回复
热议问题