Changeset 880
- Timestamp:
- 08/23/07 11:49:16 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/ipo/request/filters/stubPasswordFilter.php (modified) (3 diffs)
- trunk/src/main/resources/ipo/request.xml (modified) (1 diff)
- trunk/src/test/php/net/stubbles/integration/stubRequestValueErrorXJConfFactoryTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/request/filters/stubPasswordFilterTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/ipo/request/filters/stubPasswordFilter.php
r731 r880 32 32 */ 33 33 protected $minLength; 34 /** 35 * minimum amount of different characters in the password 36 * 37 * @var int 38 */ 39 protected $minDiffChars = 5; 34 40 /** 35 41 * list of values that are not allowed as password … … 72 78 73 79 /** 80 * set minimum amount of different characters within password 81 * 82 * Set the value with NULL to disable the check. 83 * 84 * @param int $minDiffChars 85 */ 86 public function setMinDiffChars($minDiffChars) 87 { 88 $this->minDiffChars = $minDiffChars; 89 } 90 91 /** 92 * return the minimum amount of different characters within the password 93 * 94 * @return int 95 */ 96 public function getMinDiffChars() 97 { 98 return $this->minDiffChars; 99 } 100 101 /** 74 102 * check if entered passwords fulfill password conditions 75 103 * … … 99 127 throw new stubFilterException($this->rveFactory->create('PASSWORD_INVALID')); 100 128 } 129 130 if (null !== $this->minDiffChars) { 131 if (count(count_chars($value, 1)) < $this->minDiffChars) { 132 throw new stubFilterException($this->rveFactory->create('PASSWORD_TOO_LESS_DIFF_CHARS')); 133 } 134 } 101 135 102 136 return $this->secure($value); trunk/src/main/resources/ipo/request.xml
r719 r880 53 53 <message locale="en_EN">You choose an invalid password. Please choose another password.</message> 54 54 <message locale="de_DE">Sie haben ein ungültiges Passwort angegeben. Bitte wählen Sie ein anderes Passwort.</message> 55 </messages> 56 <valueKeys /> 57 </error> 58 <error id="PASSWORD_TOO_LESS_DIFF_CHARS"> 59 <messages> 60 <message locale="en_EN">Your password has to less different characters. Please choose another password.</message> 61 <message locale="de_DE">Ihr Passwort hat zu wenig unterschiedliche Zeichen. Bitte wählen Sie ein anderes Passwort.</message> 55 62 </messages> 56 63 <valueKeys /> trunk/src/test/php/net/stubbles/integration/stubRequestValueErrorXJConfFactoryTestCase.php
r719 r880 122 122 123 123 /** 124 * test that the PASSWORD_TOO_LESS_DIFF_CHARS error is created 125 */ 126 public function testPASSWORD_TOO_LESS_DIFF_CHARS() 127 { 128 $rveFactory = new stubRequestValueErrorXJConfFactory(); 129 $requestError = $rveFactory->create('PASSWORD_TOO_LESS_DIFF_CHARS'); 130 $this->assertIsA($requestError, 'stubRequestValueError'); 131 $this->assertEqual($requestError->getId(), 'PASSWORD_TOO_LESS_DIFF_CHARS'); 132 $this->assertTrue($requestError->hasMessage('en_EN')); 133 $this->assertTrue($requestError->hasMessage('de_DE')); 134 $requestError2 = $rveFactory->create('PASSWORD_TOO_LESS_DIFF_CHARS'); 135 $this->assertClone($requestError, $requestError2); 136 } 137 138 /** 124 139 * test that the STRING_TOO_SHORT error is created 125 140 */ trunk/src/test/php/net/stubbles/ipo/request/filters/stubPasswordFilterTestCase.php
r696 r880 47 47 $this->mockStubRequestValueErrorFactory->setReturnValue('create', new stubRequestValueError('minLength', array('en_EN' => 'Something wrent wrong.'))); 48 48 $this->passwordFilter = new stubPasswordFilter($this->mockStubRequestValueErrorFactory, $this->mockMinLengthValidator); 49 $this->passwordFilter->setMinDiffChars(null); 49 50 } 50 51 … … 97 98 $this->passwordFilter->execute('bar'); 98 99 } 100 101 /** 102 * test checking for minimum amount of different characters works 103 */ 104 public function testMinDiffChars() 105 { 106 $this->passwordFilter->setMinDiffChars(5); 107 $this->mockMinLengthValidator->setReturnValue('validate', true); 108 $this->assertEqual($this->passwordFilter->execute(array('abcde', 'abcde')), md5('abcde')); 109 $this->expectException('stubFilterException'); 110 $this->passwordFilter->execute(array('abcdd', 'abcdd')); 111 } 99 112 } 100 113 ?>
