class PasswordStrength in Password Strength 8.2
Same name in this branch
- 8.2 src/PasswordStrength.php \Drupal\password_strength\PasswordStrength
- 8.2 src/Plugin/PasswordConstraint/PasswordStrength.php \Drupal\password_strength\Plugin\PasswordConstraint\PasswordStrength
Enforces a specific character length for passwords.
Plugin annotation
@PasswordConstraint(
id = "password_strength_constraint",
title = @Translation("Password Strength"),
description = @Translation("PasswordStrength is a password strength estimator using pattern matching and minimum entropy calculation. Scores range from 0 to 4, 4 being the strongest password."),
error_message = @Translation("Your password lacks strength and has too many common patterns."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\password_policy\PasswordConstraintBase implements PasswordConstraintInterface uses StringTranslationTrait
- class \Drupal\password_strength\Plugin\PasswordConstraint\PasswordStrength
- class \Drupal\password_policy\PasswordConstraintBase implements PasswordConstraintInterface uses StringTranslationTrait
Expanded class hierarchy of PasswordStrength
File
- src/
Plugin/ PasswordConstraint/ PasswordStrength.php, line 22
Namespace
Drupal\password_strength\Plugin\PasswordConstraintView source
class PasswordStrength extends PasswordConstraintBase {
public $strength_scores = [
'0' => 'Very weak (0)',
'1' => 'Weak (1)',
'2' => 'Average (2)',
'3' => 'Strong (3)',
'4' => 'Very strong (4)',
];
/**
* {@inheritdoc}
*/
function validate($password, UserInterface $user) {
$userData = array_merge($user
->getAccountName() ? [
$user
->getAccountName(),
] : [], $user
->getEmail() ? [
$user
->getEmail(),
] : []);
$configuration = $this
->getConfiguration();
$validation = new PasswordPolicyValidation();
$password_strength = new \Drupal\password_strength\PasswordStrength();
$strength = $password_strength
->passwordStrength($password, $userData);
if ($strength['score'] < $configuration['strength_score']) {
$validation
->setErrorMessage($this
->t('The password has a score of @password-score but the policy requires a score of at least @policy-score', array(
'@password-score' => $strength['score'],
'@policy-score' => $configuration['strength_score'],
)));
}
return $validation;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'strength_score' => 3,
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['strength_score'] = array(
'#type' => 'select',
'#title' => t('Password Strength Minimum Score'),
'#options' => $this->strength_scores,
'#default_value' => $this
->getConfiguration()['strength_score'],
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['strength_score'] = $form_state
->getValue('strength_score');
}
/**
* {@inheritdoc}
*/
public function getSummary() {
return $this
->t('Password Strength minimum score of @score', array(
'@score' => $this->configuration['strength_score'],
));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PasswordConstraintBase:: |
public | function | ||
PasswordConstraintBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
PasswordConstraintBase:: |
public | function |
Returns a translated description for the constraint description. Overrides PasswordConstraintInterface:: |
|
PasswordConstraintBase:: |
public | function |
Returns a translated error message for the constraint. Overrides PasswordConstraintInterface:: |
|
PasswordConstraintBase:: |
public | function |
Returns a translated string for the constraint title. Overrides PasswordConstraintInterface:: |
|
PasswordConstraintBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
PasswordConstraintBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
6 |
PasswordConstraintBase:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
1 |
PasswordStrength:: |
public | property | ||
PasswordStrength:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
PasswordStrength:: |
public | function |
Gets default configuration for this plugin. Overrides PasswordConstraintBase:: |
|
PasswordStrength:: |
public | function |
Returns a human-readable summary of the constraint. Overrides PasswordConstraintInterface:: |
|
PasswordStrength:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
PasswordStrength:: |
function |
Returns a true/false status if the password meets the constraint. Overrides PasswordConstraintInterface:: |
||
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |