Creating account type where email not required to be unique I'm developing a platform for Drupal 8 where there are several account types: students, their parents, teachers.
The students are young and we want their accounts associated with their parents' emails for security reasons, and there are cases where the parent has two or more students on the system. Also, each parent and student will have logins to their own areas.
So I need to be able to create student accounts where the email address is not required to be unique. And for the student accounts I need the password management (forgot/reset) to be done by username, not email).
Is it possible? How can I achieve this?
This answer is untested and it should serve as a guidance. Use it at your risk.

mymodule_entity_base_field_info_alter(&amp;$fields, EntityTypeInterface $entity_type) {
  if ($entity_type-&gt;id() == 'user' {
    unset($fields['mail']['constraints']['UserMailUnique']);
  }
}


If it doesn't work, try the following code.

$email_definition = &amp;$fields['mail']['constraints'];
unset($email_definition['UserMailUnique']);


As DataDefinition::&amp;offsetGet returns a reference, both should work.

Note that accessing the definition as an array is deprecated, but as long as https://www.drupal.org/node/2346329 is unresolved there's hardly anything else you could do.