Example #1
0
 /**
  * {@inheritdoc}
  */
 public function hash($password)
 {
     $hash = $this->originalPassword->hash($password);
     // Allow prefixing only if the service was asked to prefix. Check also if
     // the $password pattern is conforming to a MD5 result.
     if ($this->enabled && preg_match('/^[0-9a-f]{32}$/', $password)) {
         $hash = 'U' . $hash;
     }
     return $hash;
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 protected function save(ContentEntityInterface $entity, array $old_destination_id_values = array())
 {
     // Do not overwrite the root account password.
     if ($entity->id() != 1) {
         // Set the pre_hashed password so that the PasswordItem field does not hash
         // already hashed passwords. If the md5_passwords configuration option is
         // set we need to rehash the password and prefix with a U.
         // @see \Drupal\Core\Field\Plugin\Field\FieldType\PasswordItem::preSave()
         $entity->pass->pre_hashed = TRUE;
         if (isset($this->configuration['md5_passwords'])) {
             $entity->pass->value = 'U' . $this->password->hash($entity->pass->value);
         }
     }
     return parent::save($entity, $old_destination_id_values);
 }