Reputation: 797
I've not used Laravel before & am getting familiar; I'm on v6.15.1
My issue: I can't figure out how to change the password length requirements on the 'Reset Password' form.
What I've done:
app/Http/Controllers/Auth/RegisterController.php
- This works & the form's minimum password length validation error requires a length of 12
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:12', 'confirmed'],
]);
}
app/Http/Controllers/Auth/ResetPasswordController.php
- This does not work & I'm still getting the validation error "The password must be at least 8 characters."
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Support\Facades\Validator;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'password' => ['required', 'string', 'min:12', 'confirmed'],
]);
}
}
Upvotes: 1
Views: 170
Reputation: 797
Not entirely sure why yet until I poke around in Laravel more, but apparently the reset password controller uses a 'rules' method instead of valdiation
In app/Http/Controllers/Auth/ResetPasswordController.php
I added the construct method I added the rules method & made the password 1) require a length of 12 & 2) additional characters, numbers etc
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Where to redirect users after resetting their password.
*
* @var string
*/
protected $redirectTo = '/';
public function __construct()
{
$this->middleware('guest');
}
// this function is ovverride from ResetsPasswords Traits
protected function rules()
{
return [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|min:12|confirmed|regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\x])(?=.*[!$#%]).*$/',
];
}
}
Upvotes: 1