when i type the email and the password and i click on reset password , if the password is less then 3 characters it shows an error saying password must be at least 3 characters, but if i type a password of more then 3 characters , it shows an error in email input saying Passwords must be at least eight characters and match the confirmation, and the password is confirmed and matches the confiramtion.
rules method in the resetPasswordController.php :
protected function rules()
{
return [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:3',
];
}
and how do i solve this problem to reset the password succefully without showing Passwords must be at least eight characters and match the confirmation?
Just add rules() method, in the Auth\ResetPasswordsController.php after construct():
public function rules()
{
return [
'password' => ['required', 'min:5', 'confirmed']
];
}
Here's the screenshot, click me.
And, please, keep in mind, never edit vendor/ files.
It's hardcoded in laravel 5.8. To fix it you will need to override some of the classes.
1.) Create a CustomPasswordResetServiceProvider inside App\Providers
You need to create a new CustomPasswordResetServiceProvider class which we will use to replace the Default PasswordResetServiceProvider
<?php
namespace App\Providers;
use App\Services\CustomPasswordBrokerManager;
use Illuminate\Support\ServiceProvider;
class CustomPasswordResetServiceProvider extends ServiceProvider
{
protected $defer = true;
public function register()
{
$this->registerPasswordBrokerManager();
}
public function provides()
{
return ['auth.password'];
}
protected function registerPasswordBrokerManager()
{
$this->app->singleton('auth.password', function ($app) {
return new CustomPasswordBrokerManager($app);
});
}
}
2.) Replace Service Provider in app/config.php
Next, we need to replace the newly created ServiceProvider in our app/config.php
Open you app/config.php file and comment out PasswordResetServiceProvider and add new the ServiceProvider class.
//Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
App\Providers\CustomPasswordResetServiceProvider::class,
3.) Create new CustomPasswordBrokerManager class
Create a new class CustomPasswordBrokerManager and under directory App/Services and copy all the contents of PasswordBrokerManager which is located at Illuminate\Auth\Passwords\PasswordBrokerManager.php
Then modified the function resolve to return an instance of my CustomPasswordProvider class
protected function resolve($name)
{
$config = $this->getConfig($name);
if (is_null($config)) {
throw new InvalidArgumentException("Password resetter [{$name}] is not defined.");
}
return new CustomPasswordBroker(
$this->createTokenRepository($config),
$this->app['auth']->createUserProvider($config['provider'] ?? null)
);
}
4. Create CustomPasswordBroker
Finally, You can now create your new CustomPasswordBroker class under App/Services directory which extends the default PasswordBroker class located at Illuminate\Auth\Passwords\PasswordBroker
<?php
namespace App\Services;
use Illuminate\Auth\Passwords\PasswordBroker as BasePasswordBroker;
class CustomPasswordBroker extends BasePasswordBroker
{
/**
* Determine if the passwords are valid for the request.
*
* @param array $credentials
*
* @return bool
*/
protected function validatePasswordWithDefaults(array $credentials)
{
$minPassLength = 6;
[$password, $confirm] = [
$credentials['password'],
$credentials['password_confirmation'],
];
return $password === $confirm && mb_strlen($password) >= $minPassLength;
}
}
Now, you can override the functions that you need. Mostly you will need to start your modification with function sendResetLink and then you can take it ahead from there.
credit: https://www.5balloons.info/extending-passwordbroker-class-laravel-5/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With