SPasswordValidator Class Reference. Yii Framework

SPasswordValidator

Package extensions.spasswordvalidator
Inheritance class SPasswordValidator » CValidator » CComponent
Version 0.2
Source Code
SPasswordValidator

Validator for passwords. Ensure password is strong (at least with default parameters)

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
attributes array list of attributes to be validated. CValidator
builtInValidators array list of built-in validators (name=>class) CValidator
digit int minimal number of digit characters SPasswordValidator
enableClientValidation boolean whether to perform client-side validation. CValidator
except array list of scenarios that the validator should not be applied to. CValidator
low int minimal number of lower case characters SPasswordValidator
message string the user-defined error message. CValidator
min int minimal number of characters SPasswordValidator
on array list of scenarios that the validator should be applied. CValidator
safe boolean whether attributes listed with this validator should be considered safe for massive assignment. CValidator
skipOnError boolean whether this validation rule should be skipped when there is already a validation error for the current attribute. CValidator
spec int minimal number of special characters SPasswordValidator
up int minimal number of upper case characters SPasswordValidator

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
applyTo() Returns a value indicating whether the validator applies to the specified scenario. CValidator
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
clientValidateAttribute() Returns the JavaScript needed for performing client-side validation. CValidator
createValidator() Creates a validator object. CValidator
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent
validate() Validates the specified object. CValidator

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
addError() Adds an error about the specified attribute to the active record. CValidator
isEmpty() Checks if the given value is empty. CValidator
validateAttribute() Validation SPasswordValidator

Property Details

digit property
public int $digit;

minimal number of digit characters

low property
public int $low;

minimal number of lower case characters

min property
public int $min;

minimal number of characters

spec property
public int $spec;

minimal number of special characters

up property
public int $up;

minimal number of upper case characters

Method Details

validateAttribute() method
protected void validateAttribute(CModel $object, string $attribute)
$object CModel
$attribute string
Source Code: (show)
protected function validateAttribute($object$attribute)
{
//        $this->checkParams();
    
    
$value $object->$attribute;

    
// is a string
    
if (!is_string($value))
    {
        
$this->addError($object
                        
$attribute
                        
":attribute is a :type and is must be a string."
                        array(
':attribute' => $attribute':type' => gettype($value))
        );
        return; 
// other checks will throw errors or exception, so end validation here.
    
}

    
// number of lower case characters
    
$found preg_match_all('![a-z]!'$value$whatever);
    if (
$found $this->low)
    {
        
$this->addErrorInternal($object
                        
$attribute
                       
'lower case',
                        array(
'found' => $found'required' => $this->low)
        );            
    }

    
// number of upper case characters
    
$found preg_match_all('![A-Z]!'$value$whatever);
    if (
$found $this->up)
    {
        
$this->addErrorInternal($object
                        
$attribute
                        
'upper case',
                        array(
'found' => $found'required' => $this->up)
        );
    }
    
    
// special characters
    
$found preg_match_all('![\W]!'$value$whatever);
    if (
$found $this->spec)
    {
        
$this->addErrorInternal($object
                        
$attribute
                        
'special'
                        array(
'found' => $found'required' => $this->spec)
        );
    }

    
// digit characters
    
$found preg_match_all('![\d]!'$value$whatever);
    if (
$found $this->digit)
    {
        
$this->addErrorInternal($object
                        
$attribute
                        
'digit'
                        array(
'found' => $found'required' => $this->digit)
        );
    }

    
// minimum length
    
$this->min = (int) $this->min;
    
$found strlen($value);
    if (
$found $this->min)
    {
        
$this->addErrorInternal($object
                                
$attribute
                                
""
                                array(
'found' => $found'required' => $this->min)
        );
    }
}

Validation

Function checks whether fulfill this requirements :

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.