Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 90 lines (70 sloc) 2.029 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
<?php /*

ocPortal
Copyright (c) ocProducts, 2004-2010

See text/EN/licence.txt for full licencing information.


NOTE TO PROGRAMMERS:
Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
**** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
* @license http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
* @copyright ocProducts Ltd
* @package core
*/

/**
* Test password strength.
*
* @param string The password to check
* @return integer Password strength
*/
function test_password($password)
{
if (strlen($password) == 0 )
{
return 1;
}

$strength = 0;

/*** get the length of the password ***/
$length = strlen($password);

/*** check if password is not all lower case ***/
if (strtolower($password) != $password)
{
$strength += 1;
}

/*** check if password is not all upper case ***/
if (strtoupper($password) == $password)
{
$strength += 1;
}

/*** check string length is 8 -15 chars ***/
if ($length >= 8 && $length <= 15)
{
$strength += 1;
}

/*** check if length is 16 - 35 chars ***/
if ($length >= 16 && $length <=35)
{
$strength += 2;
}

/*** check if length greater than 35 chars ***/
if ($length > 35)
{
$strength += 3;
}

/*** get the numbers in the password ***/
$numbers = array();
preg_match_all('/[0-9]/', $password, $numbers);
$strength += count($numbers[0]);

/*** check for special chars ***/
$specialchars = array();
preg_match_all('/[|!@#$%&*\/=?,;.:\-_+~^]/', $password, $specialchars);
$strength += count($specialchars[0]);

/*** get the number of unique chars ***/
$chars = preg_split('#(.)#',$password,NULL,PREG_SPLIT_DELIM_CAPTURE);
$num_unique_chars = count(array_unique($chars)) - 1;
$strength += $num_unique_chars * 2;

/*** strength is a number 1-10; ***/
$strength = $strength > 99 ? 99 : $strength;
$strength = intval(floor($strength / 10 + 1));

return $strength;
}
Something went wrong with that request. Please try again.