Laravel 5.1 Password :: reset returns passwords.password

I have this function in the controller and I cannot reset the password because I want to change the character length to 5 digits.

public function postReset(Request $request)
{
  $this->validate($request, [
    'token' => 'required',
    'password' => 'required|confirmed|digits:5',
  ]);

  $credentials = $request->only(
    'email', 'password', 'password_confirmation', 'token'
  );

  $response = Password::reset($credentials, function ($user, $password) {
    $this->resetPassword($user, $password);
  });

  dd($response);
  switch ($response) {
    case Password::PASSWORD_RESET:
      return redirect($this->redirectPath());

    default:
      return redirect()->back()
        ->withInput($request->only('email'))
        ->withErrors(['email' => trans($response)]);
  }
}

protected function resetPassword($user, $password)
{
  $user->password = bcrypt($password);
  $user->save();
  Auth::login($user);
}

but he always says:

Oops! There were problems with your input.

Passwords must be at least six characters long and match the confirmation.

And when I added:

dd($response);

he prints:

passwords.password

Any idea how to solve this?

+4
source share
3 answers

What are you looking for in this class:

\Illuminate\Auth\Passwords\PasswordBroker

and this function

validatePasswordWithDefaults

It looks strange that it is 6hard-coded in this function. I think it's probably best to change that. Perhaps you could overload the function in your controller. Try it.

+2
source

:

'password' => 'required|confirmed|digits:5'

'password' => 'required|confirmed|min:5'
+1

, Illuminate\Auth\Passwords\PasswordBroker .

reset, validateReset, , , validateNewPassword:

public function validateNewPassword(array $credentials)
{
    list($password, $confirm) = [
        $credentials['password'],
        $credentials['password_confirmation'],
    ];

    if (isset($this->passwordValidator)) {
        return call_user_func(
            $this->passwordValidator, $credentials) && $password === $confirm;
    }

    return $this->validatePasswordWithDefaults($credentials);
}

passwordValidator . validatePasswordWithDefaults , 6 .

passwordValidator Password::validator, , , , . Password::reset.

, , 5 , .

Password::validator(function($credentials)
{
    return strlen($credentials['password']) === 5;
});
+1

Source: https://habr.com/ru/post/1614818/


All Articles