"These credentials do not match our records." 拉拉维尔 5.3



我尝试通过仪表板管理员创建更改密码成员的功能,当我尝试登录时会收到此错误,并且我确定我输入了正确的值

这是我更新会员密码的功能

public function update(Request $request, $id)
{
$rules = array(
'username'        => 'required|unique:members,username,'.$id,
'email'           => 'required|unique:members,email,'.$id,
'password'        => 'min:8',
'retype_password' => 'min:8|same:password'
);
$validator = Validator::make(Input::all(), $rules);
// process the login
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
} else {
// Input
$username       = Input::get('username');
$email          = Input::get('email');
$now            = new DateTime();
// get old password
$members = members::where('id',$id)->first();
if (!empty('password') && !empty('retype_password')) {
$password = $members->password;
}else{
$password = bcrypt(Input::get('password'));
}

// store
$store = members::find($id);
$store->status       = 1;
$store->username     = $username;
$store->email        = $email;
$store->password     = $password;
$store->updated_at   = new DateTime();
$store->save();
// redirect
return redirect('system/members')->with('success','Data successfully updated');
}
}

这是模型成员

<?php
namespace App;
use IlluminateDatabaseEloquentModel;
use AppNotificationsMemberResetPasswordNotification;
class members extends User
{
protected $table = "members";
protected $fillable = [
'username', 'email', 'password',
];
/**
* Send the password reset notification.
*
* @param  string  $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new MemberResetPasswordNotification($token));
}
}

这是我的登录功能:

public function login(Request $request)
{
$this->validateLogin($request);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}

有什么解决方案吗?

更改逻辑(if/else),没有像empty('password')empty('retype_password')这样的字段

if (!empty(Input::get('password')) && !empty(Input::get('retype_password'))) {
# new password
$password = Hash::make(Input::get('password')); 
}else{
# old Password
$password = $members->password;
}

确保此use IlluminateSupportFacadesHash;在顶部


密码重新检查Laravel有最简单的方法。

在表单中

<input type="password" name="password" >
<input type="password" name="password_confirmation" > # this should be password_confirmation retype_password filed in yours

在控制器中

只需添加此规则

'password'         => 'required|min:8|confirmed', # just add confirmed thats it

编辑

使用它登录

$username = Input::get('username');
$password = Input::get('password');
if (!Auth::attempt([ 'email' => $username, 'password' => $password])) {
# error
Session::flash('error', 'Invalid Username or Password !');
return Redirect::to('admin');
}
else {
# success
return Redirect::to('admin/dashboard');
}

你应该改变你的logic

if (empty($request->password) && empty($request->retype_password)) {
$password = $members->password;
}else{
$password = bcrypt(Input::get('password'));
}

我认为你可以像这样使用 if 条件

if ($request->input('password') && $request->input('retype_password')) {
$password = bcrypt($request->input('password'));
}else{
$password = $members->password;
}

希望这有帮助

相关内容

最新更新