function password_strength_get_flaws in Password Strength 7
Same name and namespace in other branches
- 6.2 password_strength.module \password_strength_get_flaws()
Returns an array of flaws found in the password strength.
Parameters
array $strength: An array containing password strength details.
Return value
array Array of arrays suitable for theme_item_list.
1 call to password_strength_get_flaws()
- password_strength_get_message_flaws in ./
password_strength.module - Returns helper message for password strength.
File
- ./
password_strength.module, line 531 - Provides password controls, validation, and strength checker.
Code
function password_strength_get_flaws($strength) {
$use_eg = TRUE;
$use_eg_live = FALSE;
$use_eg_live_attr = FALSE;
$flaws = array(
'length' => array(
'text' => t('Is shorter than @count characters', array(
'@count' => (int) variable_get('password_strength_default_password_length', 7),
)),
'examples' => NULL,
),
'mail' => array(
'text' => t('Matches your email address'),
'examples' => NULL,
),
'name' => array(
'text' => t('Matches your account name'),
'examples' => NULL,
),
'score' => array(
'text' => t('Is not strong enough'),
'examples' => NULL,
),
'dictionary' => array(
'text' => t('Contains dictionary words'),
'examples' => array(
'password',
),
),
'sequence' => array(
'text' => t('Has a common character sequence'),
'examples' => array(
'12345',
'abc',
),
),
'repeat' => array(
'text' => t('Includes repeated characters'),
'examples' => array(
'aaa',
'55555',
),
),
'leetspeak' => array(
'text' => t('Has leet (or “1337”), also known as eleet or leetspeak'),
'examples' => array(
'p4ssw0rd',
),
),
'spatial' => array(
'text' => t('Has a keyboard sequence'),
'examples' => array(
'qwerty',
'asdf',
),
),
'digit' => array(
'text' => t('Has a series of just digits'),
'examples' => array(
'929',
),
),
'date' => array(
'text' => t('Includes a date'),
'examples' => array(
'19-11-1978',
),
),
'year' => array(
'text' => t('Includes a year'),
'examples' => array(
'2013',
),
),
);
// Collect all matched patterns.
$matches = array();
foreach ($strength['matches'] as $match) {
$matches[$match['pattern']][] = $match['matched'];
}
// Build a list of flaws for this password.
$items = array();
foreach ($matches as $pattern => $match) {
if (!isset($flaws[$pattern])) {
continue;
}
$flaw = $flaws[$pattern];
$item = array();
$item['data'] = $flaw['text'];
// Use default examples.
if ($use_eg && !empty($flaw['text']) && !empty($flaw['examples'])) {
$item['data'] .= t(' (e.g. "@match")', array(
'@match' => implode('", "', $flaw['examples']),
));
}
// Use live examples.
if ($use_eg_live) {
$item['data'] .= t(' (e.g. "@match")', array(
'@match' => implode('", "', $match),
));
}
// Use live examples in title attributes.
if ($use_eg_live_attr) {
$hint = t('e.g. @match', array(
'@match' => implode(', ', $match),
));
$item['data'] .= ' (<span class="hint" title="' . $hint . '">?</span>)';
}
$items[] = $item;
}
return $items;
}