PHP Classes

policy function doesn't work

Recommend this page to a friend!

      PHP Password Policy class  >  All threads  >  policy function doesn't work  >  (Un) Subscribe thread alerts  
Subject:policy function doesn't work
Summary:the policy function seems to always return false
Messages:2
Author:GFAP
Date:2018-07-20 18:04:10
 

  1. policy function doesn't work   Reply   Report abuse  
Picture of GFAP GFAP - 2018-07-20 18:04:10
For some reason, even after setting rules for the policy, the policy function doesn't seem to return anything. I have called the __set() function after instaniating the class

$item = new PasswordPolicy;
$item->__set("min_length", 15);

var_dump($item->policy);

but it returns false. However, the validation function still works and returns the error message which means it partially works but the policy function doesn't?

  2. Re: policy function doesn't work   Reply   Report abuse  
Picture of Arun Vitto Arun Vitto - 2018-07-31 04:23:38 - In reply to message 1 from GFAP
Hi....
you can use the Pass rule as array in constructor like

$rules[ 'min_length' ] = 8;
$rules[ 'max_length' ] = 64;
$policy = new PasswordPolicy( $rules );

or Rules defined on object like

$policy->min_lowercase_chars = 1;
$policy->min_uppercase_chars = 1;
$policy->min_numeric_chars = 1;
$policy->min_nonalphanumeric_chars = 1;

Afterwards you can validate the password using validate method

$valid = $policy->validate( $password );
then you can find the errors by using get_errors() method


if ( !$valid ) {
foreach ( $policy->get_errors() as $k => $error ) {

echo <p class=\"error\" id=\"$k\">$error</p></font>";
}
}

Kindly try with above said flow .it is perfectly working