Laravel - 哈希检查 returns false 即使它是正确的

Laravel - Hash check returns false even when its correct

我正在使用 md5 从表单登录,我正在尝试切换到 bcrypt,但是 Hashk::check 方法总是 returns 错误,即使密码正确,知道为什么不工作?

         $email = Input::get('email');
         $password =  Input::get('password');
         $user = User::where("email","=",$email)->first();

            if(Hash::check($password,$user->password)) {

                    $userID = $user->id_user;
                    $username = $user->first_name." ".$user->last_name;
                    $admin = "yes";
                    Session::put('userID',$userID);
                    Session::put('userName',$username);
                    Session::put('admin',$admin);
                    return redirect('/cw-admin/');
            } else {
                    return Redirect::to('/cw-admin/login')
                        ->withErrors(['no' => 'Incorrect password']);
            }
            }

EDIT 添加了 User 模型,我只更改了 fillables、primaryKey 和 ID,方法留空。

class User extends Model implements Authenticatable
{

    protected $table = 'user';
    protected $primaryKey = 'id_user';

    protected $fillable = [
        'first_name','last_name','password','email'
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];
    }

dd 输出:

User {#592 ▼
  #table: "user"
  #primaryKey: "id_user"
  #fillable: array:4 [▼
    0 => "first_name"
    1 => "last_name"
    2 => "password"
    3 => "email"
  ]
  #hidden: array:2 [▼
    0 => "password"
    1 => "remember_token"
  ]
  #connection: "mysql"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:7 [▶]
  #original: array:7 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #visible: []
  #guarded: array:1 [▼
    0 => "*"
  ]
}

您必须检查您的用户 table 定义。如果 Hashed 字段返回 false,即使您向它发布内容,它也不会检索与您发布的相同的值。

在我的例子中,我会在存储散列值的列上使用最大长度。

Alter Table Users Modify password VCHAR(255);