|
From: <gem...@li...> - 2012-03-16 12:32:59
|
Revision: 553
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=553&view=rev
Author: matijsdejong
Date: 2012-03-16 12:32:50 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
Added password report option
Modified Paths:
--------------
trunk/library/classes/Gems/Default/OptionAction.php
trunk/library/classes/Gems/User/PasswordChecker.php
trunk/library/classes/Gems/User/User.php
trunk/library/classes/Gems/User/UserLoader.php
trunk/library/classes/Gems/User/UserNewPasswordValidator.php
Modified: trunk/library/classes/Gems/Default/OptionAction.php
===================================================================
--- trunk/library/classes/Gems/Default/OptionAction.php 2012-03-15 14:59:14 UTC (rev 552)
+++ trunk/library/classes/Gems/Default/OptionAction.php 2012-03-16 12:32:50 UTC (rev 553)
@@ -87,6 +87,7 @@
if ($user->isPasswordResetRequired()) {
$this->menu->setVisible(false);
+
} elseif ($user->hasPassword()) {
// Field current password
//
@@ -123,11 +124,24 @@
$element->addValidator(new MUtil_Validate_IsConfirmed('new_password', $this->_('New password')));
$form->addElement($element);
- $element = new Zend_Form_Element_Submit('submit');
- $element->setAttrib('class', 'button');
- $element->setLabel($this->_('Save'));
- $form->addElement($element);
+ // Show password info
+ if ($info = $user->reportPasswordWeakness()) {
+ foreach ($info as &$line) {
+ $line .= ',';
+ }
+ $line[strlen($line) - 1] = '.';
+ $element = new MUtil_Form_Element_Html('rules');
+ $element->setLabel($this->_('Password rules'));
+ $element->div($this->_('A password:'))->ul($info);
+ $form->addElement($element);
+
+ $element = new Zend_Form_Element_Submit('submit');
+ $element->setAttrib('class', 'button');
+ $element->setLabel($this->_('Save'));
+ $form->addElement($element);
+ }
+
/****************
* Process form *
****************/
Modified: trunk/library/classes/Gems/User/PasswordChecker.php
===================================================================
--- trunk/library/classes/Gems/User/PasswordChecker.php 2012-03-15 14:59:14 UTC (rev 552)
+++ trunk/library/classes/Gems/User/PasswordChecker.php 2012-03-16 12:32:50 UTC (rev 553)
@@ -92,7 +92,7 @@
$results = array();
if ($len && (preg_match_all('/[A-Z]/', $password, $results) < $len)) {
$this->_addError(sprintf(
- $this->translate->plural('A password should contain at least one uppercase character.', 'A password should contain at least %d uppercase characters.', $len),
+ $this->translate->plural('should contain at least one uppercase character', 'should contain at least %d uppercase characters', $len),
$len));
}
}
@@ -109,7 +109,7 @@
$results = array();
if ($len && (preg_match_all('/[a-z]/', $password, $results) < $len)) {
$this->_addError(sprintf(
- $this->translate->plural('A password should contain at least one lowercase character.', 'A password should contain at least %d lowercase characters.', $len),
+ $this->translate->plural('should contain at least one lowercase character', 'should contain at least %d lowercase characters', $len),
$len));
}
}
@@ -124,7 +124,7 @@
{
$len = intval($parameter);
if ($len && (strlen($password) < $len)) {
- $this->_addError(sprintf($this->translate->_('A password should be at least %d characters long.'), $len));
+ $this->_addError(sprintf($this->translate->_('should be at least %d characters long'), $len));
}
}
@@ -138,12 +138,14 @@
{
$len = intval($parameter);
if ($len) {
- $results = array();
- $count = preg_match_all('/[A-Za-z]/', $password, $results);
- if (strlen($password) - $count < $len) {
+ $results = array(); // Not used but required
+ $count = strlen($password) - preg_match_all('/[A-Za-z]/', $password, $results);
+ if (($len > 0) && ($count < $len)) {
$this->_addError(sprintf(
- $this->translate->plural('A password should contain at least one not alphabetic character.', 'A password should contain at least %d not alphabetic characters.', $len),
+ $this->translate->plural('should contain at least one non alphabetic character', 'should contain at least %d non alphabetic characters', $len),
$len));
+ } elseif (($len < 0) && (($count > 0) || (null === $password))) {
+ $this->_addError($this->translate->_('should not contain non alphabetic characters'));
}
}
}
@@ -158,12 +160,14 @@
{
$len = intval($parameter);
if ($len) {
- $results = array();
- $count = preg_match_all('/[A-Za-z]/', $password, $results);
- if (strlen($password) - $count < $len) {
+ $results = array(); // Not used but required
+ $count = strlen($password) - preg_match_all('/[0-9A-Za-z]/', $password, $results);
+ if (($len > 0) && ($count < $len)) {
$this->_addError(sprintf(
- $this->translate->plural('A password should contain at least one not alphanumeric character.', 'A password should contain at least %d not alphanumeric characters.', $len),
+ $this->translate->plural('should contain at least one non alphanumeric character', 'should contain at least %d non alphanumeric characters', $len),
$len));
+ } elseif (($len < 0) && (($count > 0) || (null === $password))) {
+ $this->_addError($this->translate->_('should not contain non alphanumeric characters'));
}
}
}
@@ -180,8 +184,8 @@
if ($on) {
$lpwd = strtolower($password);
- if (false !== strpos($lpwd, strtolower($this->user->getLoginName()))) {
- $this->_addError($this->translate->_('A password should not contain the login name.'));
+ if ((false !== strpos($lpwd, strtolower($this->user->getLoginName()))) || (null === $password)) {
+ $this->_addError(sprintf($this->translate->_('should not contain your login name "%s"'), $this->user->getLoginName()));
}
}
}
@@ -195,18 +199,24 @@
protected function numCount($parameter, $password)
{
$len = intval($parameter);
- $results = array();
- if ($len && (preg_match_all('/[0-9]/', $password, $results) < $len)) {
- $this->_addError(sprintf(
- $this->translate->plural('A password should contain at least one number.', 'A password should contain at least %d numbers.', $len),
- $len));
+ if ($len) {
+ $results = array(); // Not used but required
+ $count = preg_match_all('/[0-9]/', $password, $results);
+ if (($len > 0) && ($count < $len)) {
+ $this->_addError(sprintf(
+ $this->translate->plural('should contain at least one number', 'should contain at least %d numbers', $len),
+ $len));
+ } elseif (($len < 0) && (($count > 0) || (null === $password))) {
+ $this->_addError($this->translate->_('may not contain numbers'));
+ }
}
}
/**
* Check for password weakness.
*
- * @param string $password
+ * @param Gems_User_User $user
+ * @param string $password Or null when you want a report on all the rules for this password.
* @param array $codes An array of code names that identify rules that should be used only for those codes.
* @return mixed String or array of strings containing warning messages
*/
Modified: trunk/library/classes/Gems/User/User.php
===================================================================
--- trunk/library/classes/Gems/User/User.php 2012-03-15 14:59:14 UTC (rev 552)
+++ trunk/library/classes/Gems/User/User.php 2012-03-16 12:32:50 UTC (rev 553)
@@ -730,10 +730,10 @@
/**
* Check for password weakness.
*
- * @param string $password
+ * @param string $password Or null when you want a report on all the rules for this password.
* @return mixed String or array of strings containing warning messages or nothing
*/
- public function reportPasswordWeakness($password)
+ public function reportPasswordWeakness($password = null)
{
if ($this->canSetPassword()) {
$checker = $this->userLoader->getPasswordChecker();
Modified: trunk/library/classes/Gems/User/UserLoader.php
===================================================================
--- trunk/library/classes/Gems/User/UserLoader.php 2012-03-15 14:59:14 UTC (rev 552)
+++ trunk/library/classes/Gems/User/UserLoader.php 2012-03-16 12:32:50 UTC (rev 553)
@@ -431,13 +431,11 @@
* Check for password weakness.
*
* @param Gems_User_User $user The user for e.g. name checks
- * @param string $password
+ * @param string $password Or null when you want a report on all the rules for this password.
* @return mixed String or array of strings containing warning messages
*/
- public function reportPasswordWeakness(Gems_User_User $user, $password)
+ public function reportPasswordWeakness(Gems_User_User $user, $password = null)
{
- $checker = $this->_getClass('passwordChecker');
-
return $user->reportPasswordWeakness($password);
}
Modified: trunk/library/classes/Gems/User/UserNewPasswordValidator.php
===================================================================
--- trunk/library/classes/Gems/User/UserNewPasswordValidator.php 2012-03-15 14:59:14 UTC (rev 552)
+++ trunk/library/classes/Gems/User/UserNewPasswordValidator.php 2012-03-16 12:32:50 UTC (rev 553)
@@ -84,6 +84,10 @@
{
$this->_report = $this->_user->reportPasswordWeakness($value);
+ foreach ($this->_report as &$report) {
+ $report = ucfirst($report) . '.';
+ }
+
// MUtil_Echo::track($value, $this->_report);
return ! (boolean) $this->_report;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|