diff --git a/composer.json b/composer.json
index edab18f..be060ea 100644
--- a/composer.json
+++ b/composer.json
@@ -32,7 +32,7 @@
         "source": "https://git.drupalcode.org/project/email_registration"
     },
     "require": {
-        "drupal/core": "^8.7.7 || ^9"
+        "drupal/core": "^9.1 || ^10"
     },
     "conflict": {
         "drupal/commerce": "<2.12"
diff --git a/email_registration.info.yml b/email_registration.info.yml
index 9259222..253c340 100644
--- a/email_registration.info.yml
+++ b/email_registration.info.yml
@@ -1,6 +1,6 @@
 name: Email Registration
 type: module
 description: 'Allows users to register with an email address as their username.'
-core_version_requirement: ^8.7.7 || ^9
+core_version_requirement: ^9.1 || ^10
 dependencies:
   - drupal:user
diff --git a/email_registration.module b/email_registration.module
index 3a99b68..489878e 100644
--- a/email_registration.module
+++ b/email_registration.module
@@ -135,7 +135,7 @@ function email_registration_form_user_form_alter(&$form, FormStateInterface $for
     /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
     $form_object = $form_state->getFormObject();
     if ($form_object->getEntity()->isNew()) {
-      $form['account']['name']['#value'] = 'email_registration_' . user_password();
+      $form['account']['name']['#value'] = 'email_registration_' . \Drupal::service('password_generator')->generate();
     }
   }
   $form['account']['mail']['#title'] = t('Email');
diff --git a/src/Plugin/Commerce/CheckoutPane/EmailRegistrationCompletionRegistration.php b/src/Plugin/Commerce/CheckoutPane/EmailRegistrationCompletionRegistration.php
index e4cca11..c3ad0eb 100644
--- a/src/Plugin/Commerce/CheckoutPane/EmailRegistrationCompletionRegistration.php
+++ b/src/Plugin/Commerce/CheckoutPane/EmailRegistrationCompletionRegistration.php
@@ -26,7 +26,7 @@ class EmailRegistrationCompletionRegistration extends CompletionRegister {
     // Set the name as per email_registration_form_user_register_form_alter().
     $pane_form['name'] = [
       '#type' => 'hidden',
-      '#value' => 'email_registration_' . user_password(),
+      '#value' => 'email_registration_' . \Drupal::service('password_generator')->generate(),
     ];
 
     // Try and help password managers.
diff --git a/src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php b/src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php
index a809f3a..216d7a1 100644
--- a/src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php
+++ b/src/Plugin/Commerce/CheckoutPane/EmailRegistrationLogin.php
@@ -90,7 +90,7 @@ class EmailRegistrationLogin extends Login {
     $complete_form['#cache']['tags'][] = 'config:email_registration.settings';
 
     $pane_form['register']['name']['#type'] = 'value';
-    $pane_form['register']['name']['#value'] = 'email_registration_' . user_password();
+    $pane_form['register']['name']['#value'] = 'email_registration_' . \Drupal::service('password_generator')->generate();
     $pane_form['register']['mail']['#title'] = $this->t('Email');
 
     return $pane_form;
diff --git a/tests/src/Functional/EmailRegistrationTestCase.php b/tests/src/Functional/EmailRegistrationTestCase.php
index 74b3012..3c20bd3 100644
--- a/tests/src/Functional/EmailRegistrationTestCase.php
+++ b/tests/src/Functional/EmailRegistrationTestCase.php
@@ -43,14 +43,16 @@ class EmailRegistrationTestCase extends BrowserTestBase {
       'pass[pass1]' => $pass,
       'pass[pass2]' => $pass,
     ];
-    $this->drupalPostForm('/user/register', $register, 'Create new account');
+    $this->drupalGet('/user/register');
+    $this->submitForm($register, 'Create new account');
     $this->drupalLogout();
 
     $login = [
       'name' => $name . '@example.com',
       'pass' => $pass,
     ];
-    $this->drupalPostForm('user/login', $login, 'Log in');
+    $this->drupalGet('user/login');
+    $this->submitForm($login, 'Log in');
 
     // Really basic confirmation that the user was created and logged in.
     $this->assertSession()->responseContains('<title>' . $name . ' | Drupal</title>');
@@ -67,7 +69,8 @@ class EmailRegistrationTestCase extends BrowserTestBase {
       'name' => $name,
       'pass' => $pass,
     ];
-    $this->drupalPostForm('user/login', $login, 'Log in');
+    $this->drupalGet('user/login');
+    $this->submitForm($login, 'Log in');
     // When login_with_username is false, a user cannot login with just their
     // username.
     $this->assertSession()->responseContains('Unrecognized email address or password.');
@@ -77,7 +80,8 @@ class EmailRegistrationTestCase extends BrowserTestBase {
     $this->drupalGet('user/login');
     $this->assertSession()->responseContains('Enter your email address or username.');
     $this->assertSession()->responseContains('Email or username');
-    $this->drupalPostForm('user/login', $login, 'Log in');
+    $this->drupalGet('user/login');
+    $this->submitForm($login, 'Log in');
     // When login_with_username is true, a user can login with just their
     // username.
     $this->assertSession()->responseContains('<title>' . $name . ' | Drupal</title>');
@@ -93,7 +97,8 @@ class EmailRegistrationTestCase extends BrowserTestBase {
       'pass[pass1]' => $pass,
       'pass[pass2]' => $pass,
     ];
-    $this->drupalPostForm('/user/register', $register, 'Create new account');
+    $this->drupalGet('/user/register');
+    $this->submitForm($register, 'Create new account');
     // User properly created, immediately logged in.
     $this->assertSession()->responseContains('Registration successful. You are now logged in.');
 
@@ -114,7 +119,8 @@ class EmailRegistrationTestCase extends BrowserTestBase {
       'pass[pass1]' => $pass,
       'pass[pass2]' => $pass,
     ];
-    $this->drupalPostForm('/user/register', $register, 'Create new account');
+    $this->drupalGet('/user/register');
+    $this->submitForm($register, 'Create new account');
     $account = user_load_by_mail($register['mail']);
     $this->assertSame($next_unique_name, $account->getAccountName());
     $this->drupalLogout();
@@ -123,8 +129,9 @@ class EmailRegistrationTestCase extends BrowserTestBase {
     $user = $this->createUser();
     $name = $user->label();
     $this->drupalLogin($user);
-    $this->drupalPostForm('/user/' . $user->id() . '/edit', [], 'Save');
-    $this->assertEqual($name, User::load($user->id())->label(), 'Username should not change after empty edit.');
+    $this->drupalGet('/user/' . $user->id() . '/edit');
+    $this->submitForm([], 'Save');
+    $this->assertEquals($name, User::load($user->id())->label(), 'Username should not change after empty edit.');
     $this->drupalLogout();
     $this->drupalLogin($user);
     $this->assertSame($next_unique_name, $account->getAccountName());
@@ -155,8 +162,9 @@ class EmailRegistrationTestCase extends BrowserTestBase {
     // Test that the field is set to type=value.
     $this->assertSession()->fieldNotExists('edit-name');
     $this->assertSession()->pageTextContains($username);
+    $this->drupalGet('user/' . $user->id() . '/edit');
     // Make sure the email isn't changed on save.
-    $this->drupalPostForm('user/' . $user->id() . '/edit', [], 'Save');
+    $this->submitForm([], 'Save');
     $this->assertSession()->pageTextContains($username);
   }
 
