Home>Article>PHP Framework> Teach you how to easily implement password strength verification in Laravel!

Teach you how to easily implement password strength verification in Laravel!

藏色散人
藏色散人 forward
2023-03-20 16:28:14 1628browse

This article brings you relevant knowledge about Laravel. It mainly talks about how to implement password strength verification in Laravel? Friends who are interested can take a look below. I hope it will be helpful to everyone.

Teach you how to easily implement password strength verification in Laravel!

laravel password strength verification

Requirements

I hope the laravel framework allows users to enter Password strength can be conveniently specified when using the password
Includes:

  • ##"letters" => ":attribute must contain at least one letter.",

  • "case_diff" => ":attribute must contain uppercase and lowercase letters.",

  • "numbers" => ":attribute must contain at least one number.",

  • "symbols" => ":attribute must contain at least one symbol.",

    It can be verified either mixedly or individually.
    Official website: https://packagist.org/packages/schuppo/password-strength

Implementation:

1. Execute composer Install

Laravel 6 and above according to the following scheme

composer require schuppo/password-strength:"~2.0"

Laravel 5 according to the following scheme

composer require schuppo/password-strength:"~1.5"

2. Copy the language file

Copy the following 4 lines Go to your own corresponding validation.php in resources/lang

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

3. Usage method

In the following code, the password that the user is required to enter must be at least 6 digits and contain at least one lowercase letter. and contain at least one uppercase letter and at least one number.

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 '正确';}

Summary

It smells so good!

Recommended learning: "

laravel video tutorial"

The above is the detailed content of Teach you how to easily implement password strength verification in Laravel!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete