Home > OS >  Laravel password strength validation
Laravel password strength validation

Time:04-07

Is there any better way to validate password, I know below

'password' => 'required| min:6| regex:/^.(?=.{3,})(?=.[a-zA-Z])(?=.[0-9])(?=.[\d\x])(?=.[!$#%]).$/| confirmed',

CodePudding user response:

You can try Laravel docs as well

Neither Just try below,

'password' => [
            'required',
            'string',
            'min:10',             // must be at least 10 characters in length
            'regex:/[a-z]/',      // must contain at least one lowercase letter
            'regex:/[A-Z]/',      // must contain at least one uppercase letter
            'regex:/[0-9]/',      // must contain at least one digit
            'regex:/[@$!%*#?&]/', // must contain a special character
        ],

CodePudding user response:

Here you can find much more good solution Laravel Docs

use Illuminate\Validation\Rules\Password;

// Require at least 8 characters...
Password::min(8)
 
// Require at least one letter...
Password::min(8)->letters()
 
// Require at least one uppercase and one lowercase letter...
Password::min(8)->mixedCase()
 
// Require at least one number...
Password::min(8)->numbers()
 
// Require at least one symbol...
Password::min(8)->symbols()
  • Related