Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Backend Development
1 min read

Implementing Password Strength Validation in Laravel with schuppo/password-strength

This guide explains how to install the schuppo/password-strength package in Laravel, configure custom validation messages for letters, case differences, numbers, and symbols, and apply these rules in a validator to enforce strong passwords such as a minimum length with mixed character types.

Requirement: In Laravel, allow users to specify password strength rules such as requiring at least one letter, case‑sensitive letters, numbers, or symbols, either combined or individually.

Install the package from Packagist (schuppo/password-strength) via Composer. For Laravel 6+ use composer require schuppo/password-strength:"~2.0"; for Laravel 5 use composer require schuppo/password-strength:"~1.5".

Copy the language lines into your project's resources/lang/.../validation.php file:

"letters" => ":attribute 必须包含至少一个字母。",
"case_diff" => ":attribute 必须包含大小写字母。",
"numbers" => ":attribute 必须包含至少一个数字。",
"symbols" => ":attribute 必须包含至少一个符号。"

Use the custom rules in a validator, for example requiring a password of at least six characters, containing both lower‑ and upper‑case letters and at least one digit:

public function post(Request $request){
    $validator = Validator::make($request->all(), [
        'name' => 'bail',
        'password' => ['bail','required','min:6','case_diff','numbers']
    ]);
    if ($validator->fails()) {
        return $validator->errors()->first();
    }
    return '正确';
}

The article concludes with a brief, informal remark.

For attribution, corrections or content rights, contactadmin@besthub.dev

Report an issue with this article

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion