langleyfoxall / laravel-nist-password-rules

🔒 Laravel validation rules that follow the password related recommendations found in NIST Special Publication 800-63B section 5.
GNU Lesser General Public License v3.0
208 stars 49 forks source link

Custom messages for rules validation #24

Closed poseso closed 4 years ago

poseso commented 4 years ago

I'm trying to give my own custom messages to the validation rules but can't find how to setMessage for these ones:

laravel-nist-password-rules::validation.can-not-be-sequential-characters laravel-nist-password-rules::validation.found-in-data-breach

i'm using form request for this purpose:

public function rules()
{
    return [
        'password' => array_merge(
            [
                new UnusedPassword((int) $this->segment(4)),
                (new BreachedPasswords())->setMessage(__('La contraseña ha sido expuesta en una violación de datos.')),
            ],
            PasswordRules::changePassword($this->email)
        ),
    ];
}

public function messages()
{
    return [
        'password.min' => __('La contraseña debe tener al menos 8 caracteres.'),
    ];
}

Custom message for BreachedPasswords() works but can't do the same for:

        new SequentialCharacters(),
        new RepetitiveCharacters(),

is this possible ?

Thanks

DivineOmega commented 4 years ago

Run the following at the root of your project:

php artisan vendor:publish --provider="LangleyFoxall\LaravelNISTPasswordRules\ServiceProvider"

Then take a look the files within /resources/lang/vendor/laravel-nist-password-rules/. You should be able to create a new directory (copy the en one) for your desired language, and then alter the validation.php file within it. Ensure you then change your app's locale within the config/app.php file.

poseso commented 4 years ago

Works good using the lang vendor files, is it possible to manually set the message instead of using the lang files ?

DivineOmega commented 4 years ago

Using language files is the more standard way to do it. That's how you alter the content for the built in Laravel validation messages too.

poseso commented 4 years ago

Ok good! thank you!