you can make trait to hold the general rules for validating password in any form . and concat this trait rules array with your specific form rule for a password
Password validation reccomendations
Hi all, I have been looking at password requirements for a couple of sites I am working on and how to perform validation on these. Ideally I want the password to confirm to several complexity requirements but I want to try and centralise this validation.
At the moment I have a signup, reset password and user profile edit page where the password can be set, this is 3 sets of validation rules.
I am thinking about creating a single password validator object and running the validate method alongside the main form validation for each of the 3 situations.
Has anyone tackled this problem before or have any good ideas? Thanks
For reference I am not using a command bus on either of these projects.
I think the cleanest way would be to create your own custom rules for password http://laravel.com/docs/4.2/validation#custom-validation-rules .
class CustomValidator extends Illuminate\Validation\Validator {
public function validatePassword($attribute, $value, $parameters)
{
$length = $this->validateMin($attribute, $value, 8); // Minimum 8 char
$whatever = $this->validateWhatever($attribute, $value, 'whatever parameter') // Whatever other rules
// ... other rules
// Return true if all rules passed
return $length && $whatever && ...;
}
}
Then extends the validator (in the app service provider for example)
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new CustomValidator($translator, $data, $rules, $messages);
});
Please or to participate in this conversation.