Perforce Chronicle 2012.2/486814
API Documentation

P4_Validate_StrongPassword Class Reference

Provides password strength validation according to server security requirements. More...

Inheritance diagram for P4_Validate_StrongPassword:
P4_Validate_Abstract

List of all members.

Public Member Functions

 __construct ()
 Initialize the message templates.
 isValid ($value)
 Check if value is strong password according to server requirements for strong password.

Public Attributes

const WEAK_PASSWORD = 'weakPassword'

Protected Member Functions

 _containsLowercaseLetter ($value)
 Return true if value contains at least one lowercase letter, otherwise return false.
 _containsNonAlphabetic ($value)
 Return true if value contains at least one nonalphabetic character, otherwise return false.
 _containsUppercaseLetter ($value)
 Return true if value contains at least one uppercase letter, otherwise return false.

Protected Attributes

 $_messageTemplates = null

Detailed Description

Provides password strength validation according to server security requirements.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Constructor & Destructor Documentation

P4_Validate_StrongPassword::__construct ( )

Initialize the message templates.

    {
        $this->_messageTemplates = array(
            self::WEAK_PASSWORD =>
                "Passwords must be at least 8 characters long and contain "
              . "mixed case or both alphabetic and non-alphabetic characters."
        );
    }

Member Function Documentation

P4_Validate_StrongPassword::_containsLowercaseLetter ( value) [protected]

Return true if value contains at least one lowercase letter, otherwise return false.

Parameters:
string$valuepassword
Returns:
boolean
    {
        return preg_match("/[a-z]+/", $value);
    }
P4_Validate_StrongPassword::_containsNonAlphabetic ( value) [protected]

Return true if value contains at least one nonalphabetic character, otherwise return false.

Parameters:
string$valuepassword
Returns:
boolean
    {
        return preg_match("/[^a-zA-Z]+/", $value);
    }
P4_Validate_StrongPassword::_containsUppercaseLetter ( value) [protected]

Return true if value contains at least one uppercase letter, otherwise return false.

Parameters:
string$valuepassword
Returns:
boolean
    {
        return preg_match("/[A-Z]+/", $value);
    }
P4_Validate_StrongPassword::isValid ( value)

Check if value is strong password according to server requirements for strong password.

Parameters:
string$valuepassword
Returns:
boolean
    {
        $this->_setValue($value);

        $conditionsMet = 0;
        if ($this->_containsUppercaseLetter($value)) {
            $conditionsMet++;
        }
        if ($this->_containsLowercaseLetter($value)) {
            $conditionsMet++;
        }
        if ($this->_containsNonAlphabetic($value)) {
            $conditionsMet++;
        }

        if (strlen($value) < 8 || $conditionsMet < 2) {
            $this->_error(self::WEAK_PASSWORD);
            return false;
        }

        return true;
    }

Member Data Documentation

P4_Validate_StrongPassword::$_messageTemplates = null [protected]

Reimplemented from P4_Validate_Abstract.


The documentation for this class was generated from the following file: