<?php
/**
* psl, password security level function,
* checks security level of a password.
*
* psl(&$password:String):UInt32
*
* @param String generic password by reference
* @return UInt32 security level from 0 to 3
* ------------------------------------------
* Security Level Values
*
* 0 You shouldn't allow this kind of passwords
* 1 Low Security, less than 5 seconds with a brute force
* 2 Medium Security, should be good enought
* 3 High Security, really difficult to brute force
* ------------------------------------------
* @author Andrea Giammarchi
* @site http://www.devpro.it/
* @date 2006 / 11 / 13
* @version 1.1
* @compatibility PHP >= 4
*/
function psl(&$pwd){
$match = create_function('$reg, &$pwd', 'return preg_match($reg, $pwd);');
$length = strlen($pwd);
$level = 0;
if($length > 5) {
$level = 1;
if($length > 6) {
if($match('/[a-z]/', $pwd) && $match('/[A-Z]/', $pwd) && $match('/[0-9]/', $pwd))
$level = 3;
else if(
($match('/[a-z]/', $pwd) && ($match('/[A-Z]/', $pwd) || $match('/[0-9]/', $pwd))) ||
($match('/[0-9]/', $pwd) && ($match('/[A-Z]/', $pwd) || $match('/[a-z]/', $pwd))) ||
($match('/[A-Z]/', $pwd) && ($match('/[a-z]/', $pwd) || $match('/[0-9]/', $pwd)))
)
$level = $match('/[\x20-\x2F]|[\x3A-\x40]|[\x5b-\x60]|[\x7B-\xFF]/', $pwd) ? 3 : 2;
};
};
return $level;
};
?>