3

I want to validate entered user password for complex character password,

Is there any package or method for this validation ?

MajAfy
  • 3,007
  • 10
  • 47
  • 83

2 Answers2

2

this may help a lot to set at client side, or you can create similar at server side for regex pattern.

var password = document.getElementById('pswdfield').value;
var validLength = /.{8}/.test(password);
var hasCaps = /[A-Z]/.test(password);
var hasNums = /\d/.test(password);
var hasSpecials = /[~!,@#%&_\$\^\*\?\-]/.test(password);

var isValid = validLength && hasCaps && hasNums && hasSpecials;

in $rules validation array add

'password'=>'required|regex:/^.*(?=.{3,})(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\d\X])(?=.*[!$#%]).*$/'
codebob
  • 81
  • 5
1

If you want to use package give a try with this package.

https://packagist.org/search/?q=password-strength https://github.com/schuppo/PasswordStrengthPackage

And if you want to accomplish that using regular expression check this question. Here you'll find a detailed answer.

Laravel password validation rule

Community
  • 1
  • 1
Mahfuzul Alam
  • 3,057
  • 14
  • 15