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:141740browse

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

<p>composer require schuppo/password-strength:"~2.0"<br></p>
Laravel 5 according to the following scheme

<p>composer require schuppo/password-strength:"~1.5"<br></p>
2. Copy the language file

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

<p>  "letters" => ":attribute 必须包含至少一个字母。",<br>    "case_diff" => ":attribute 必须包含大小写字母。",<br>    "numbers" => ":attribute 必须包含至少一个数字。",<br>    "symbols" => ":attribute 必须包含至少一个符号。",<br></p>
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.

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

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