【问题标题】:Laravel Auth::attempt() Fails after password changeLaravel Auth::attempt() 更改密码后失败
【发布时间】:2014-08-27 16:57:45
【问题描述】:

我的 Laravel 身份验证运行良好。我包括密码更改功能。更改密码后,除了第一个用户(uid =“1”)之外的所有用户都可以正常登录。只有默认密码哈希适用于此用户。对于其他密码哈希,登录尝试失败。我的代码如下:

用户控制器登录

 public function postSignin() {
    if (Auth::attempt(array('email'=>Input::get('email'),   'password'=>Input::get('password')))) {
        return Redirect::to('users/dashboard')->with(array('message' => 'You are now  logged in!', 'email' => Input::get('email')));
    } else {
        return Redirect::to('users/login')
        ->with('message', 'Your username/password combination was incorrect')
        ->withInput();
    }

  }

表架构

   Schema::create('users', function($table)
        {
            $table->increments('id');
            $table->string('firstname', 20);
            $table->string('lastname', 20);
            $table->string('email', 100)->unique();
            $table->string('password', 255);
            $table->string('remember_token', 255);
            $table->timestamps();
        });

密码更改控制器功能

  public function postUpass() {
    $user = User::find(Input::get('uid'));
    if((Input::get('password'))==(Input::get('passconf'))){
        $user->password = Hash::make(trim(Input::get('password')));
        $user->save();
        echo "Done";
        //echo Hash::make(trim(Input::get('password')));
    }
    else {
        echo "Check Passwords Again";
    }

请有人帮我解决这个问题。

【问题讨论】:

    标签: php authentication laravel laravel-4


    【解决方案1】:

    我还不能发表评论,所以我必须通过发布答案来征求您的意见。虽然我还想建议更改您在 postUpass 函数中访问用户的方式,因为最终用户可以轻松更改以更新另一个用户的密码。

    //change this
    $user = User::find(Input::get('uid'));
    //to this
    $user = Auth::user();
    //since the user needs to be logged in 
    //to change their password anyway
    

    另外,您是说一旦您发布到 postUpass 函数,您总是会收到“再次检查密码”通知?

    【讨论】:

      猜你喜欢
      • 2017-04-28
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      • 2018-05-20
      • 2013-04-06
      • 2017-09-13
      • 1970-01-01
      • 2014-05-22
      相关资源
      最近更新 更多