我的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";
}
有人请帮帮我。
答案 0 :(得分:0)
我还不能发表评论,所以我必须通过发帖回答你的观点。虽然我还建议您更改在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功能,您将始终返回“再次检查密码”。注意到?