Changeset 880

Show
Ignore:
Timestamp:
08/23/07 11:49:16 (1 year ago)
Author:
mikey
Message:

added check for minimum amount of different characters in stubPasswordFilter

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/request/filters/stubPasswordFilter.php

    r731 r880  
    3232     */ 
    3333    protected $minLength; 
     34    /** 
     35     * minimum amount of different characters in the password 
     36     * 
     37     * @var  int 
     38     */ 
     39    protected $minDiffChars     = 5; 
    3440    /** 
    3541     * list of values that are not allowed as password 
     
    7278 
    7379    /** 
     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    /** 
    74102     * check if entered passwords fulfill password conditions 
    75103     * 
     
    99127            throw new stubFilterException($this->rveFactory->create('PASSWORD_INVALID')); 
    100128        } 
     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        } 
    101135 
    102136        return $this->secure($value); 
  • trunk/src/main/resources/ipo/request.xml

    r719 r880  
    5353      <message locale="en_EN">You choose an invalid password. Please choose another password.</message> 
    5454      <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> 
    5562    </messages> 
    5663    <valueKeys /> 
  • trunk/src/test/php/net/stubbles/integration/stubRequestValueErrorXJConfFactoryTestCase.php

    r719 r880  
    122122 
    123123    /** 
     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    /** 
    124139     * test that the STRING_TOO_SHORT error is created 
    125140     */ 
  • trunk/src/test/php/net/stubbles/ipo/request/filters/stubPasswordFilterTestCase.php

    r696 r880  
    4747        $this->mockStubRequestValueErrorFactory->setReturnValue('create', new stubRequestValueError('minLength', array('en_EN' => 'Something wrent wrong.'))); 
    4848        $this->passwordFilter = new stubPasswordFilter($this->mockStubRequestValueErrorFactory, $this->mockMinLengthValidator); 
     49        $this->passwordFilter->setMinDiffChars(null); 
    4950    } 
    5051 
     
    9798        $this->passwordFilter->execute('bar'); 
    9899    } 
     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    } 
    99112} 
    100113?>