PasswordAnonymizer.php in General Data Protection Regulation 8
File
modules/anonymizer/src/Plugin/Anonymizer/PasswordAnonymizer.php
View source
<?php
namespace Drupal\anonymizer\Plugin\Anonymizer;
use Drupal\anonymizer\Anonymizer\AnonymizerBase;
use Drupal\anonymizer\Service\FakerServiceInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Password\PasswordInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PasswordAnonymizer extends AnonymizerBase {
const MIN_PASSWORD_LENGTH = 10;
const MAX_PASSWORD_LENGTH = 20;
protected $password;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('password'), $container
->get('anonymizer.faker'));
}
public function __construct(array $configuration, $plugin_id, $plugin_definition, PasswordInterface $password, FakerServiceInterface $faker) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $faker);
$this->password = $password;
}
public function anonymize($input, FieldItemListInterface $field = NULL) {
return $this->password
->hash($this->faker
->generator()
->password(self::MIN_PASSWORD_LENGTH, self::MAX_PASSWORD_LENGTH));
}
}