UserPasswordValidator

Type
Class
Namespace
craft\validators
Inherits
craft\validators\UserPasswordValidator » yii\validators\StringValidator » yii\validators\Validator » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

Class UserPasswordValidator.

View source

Public Properties

PropertyDescription
$attributeNamesarray – Attribute names.
$attributesarray, string – Attributes to be validated by this validator.
$behaviorsyii\base\Behavior – List of behaviors attached to this component
$builtInValidatorsarray – List of built-in validators (name => class or configuration)
$currentPasswordstring, null – The user's current (hashed) password.
$enableClientValidationboolean – Whether to enable client-side validation for this validator.
$encodingstring – The encoding of the string value to be validated (e.g. 'UTF-8').
$exceptarray, string – Scenarios that the validator should not be applied to.
$forceDifferentboolean – Whether the password must be different from the existing password.
$isEmptycallable – A PHP callable that replaces the default implementation of isEmpty().
$lengthinteger, array – Specifies the length limit of the value to be validated.
$maxinteger – Maximum length.
$messagestring – User-defined error message used when the value is not a string.
$mininteger – Minimum length.
$notEqualstring – User-defined error message used when the length of the value is not equal to $length.
$onarray, string – Scenarios that the validator can be applied to.
$sameAsCurrentstring, null – User-defined error message used when the new password is the same as $currentPassword.
$skipOnEmptyboolean – Whether this validation rule should be skipped if the attribute value is null or an empty string.
$skipOnErrorboolean – Whether this validation rule should be skipped if the attribute being validated already has some validation error according to some previous rules.
$tooLongstring – User-defined error message used when the length of the value is greater than $max.
$tooShortstring – User-defined error message used when the length of the value is smaller than $min.
$whencallable – A PHP callable whose return value determines whether this validator should be applied.
$whenClientstring – A JavaScript function name whose return value determines whether this validator should be applied on the client-side.

$currentPassword

Type
string, null

The user's current (hashed) password.

View source

Signature

public string, null $currentPassword = null

$forceDifferent

Type
boolean

Whether the password must be different from the existing password.

View source

Signature

public boolean $forceDifferent = false

$sameAsCurrent

Type
string, null

User-defined error message used when the new password is the same as $currentPassword.

View source

Signature

public string, null $sameAsCurrent = null

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__unset()Sets an object property to null.
addError()Adds an error about the specified attribute to the model object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
clientValidateAttribute()Returns the JavaScript needed for performing client-side validation.
createValidator()Creates a validator object.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
getAttributeNames()Returns cleaned attribute names without the ! character at the beginning.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getClientOptions()Returns the client-side validation options.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
isActive()Returns a value indicating whether the validator is active for the given scenario and attribute.
isEmpty()Checks if the given value is empty.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
trigger()Triggers an event.
validate()Validates a given value.
validateAttribute()Validates a single attribute.
validateAttributes()Validates the specified object.

__construct()

Constructor.

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call init().

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.

View source

Arguments

  • $config (array) – Name-value pairs that will be used to initialize the object properties

Signature

public void __construct ( array $config = [] )

init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

View source

Signature

public void init ( )

isEmpty()

Checks if the given value is empty.

A value is considered empty if it is null, an empty array, or an empty string. Note that this method is different from PHP empty(). It will return false when the value is 0.

View source

Arguments

  • $value (mixed) – The value to be checked

Returns

boolean – Whether the value is empty

Signature

public boolean isEmpty ( $value )

validateAttribute()

Validates a single attribute.

Child classes must implement this method to provide the actual validation logic.

View source

Arguments

  • $model (yii\base\Model) – The data model to be validated
  • $attribute (string) – The name of the attribute to be validated.

Signature

public void validateAttribute ( $model, $attribute )

Protected Methods

MethodDescription
formatMessage()Formats a mesage using the I18N, or simple strtr if \Yii::$app is not available.
validateValue()Validates a value.