User can't login after created programmatically

Created on 5 February 2023, over 1 year ago
Updated 10 May 2023, about 1 year ago

I can't log in via username and password which was created programmatically using code, but when I reset the password via the admin page it's working perfectly.

To replicate the issue, the following can be done:
1. Add a script to create a user in your test module:

<?php

use Drupal\user\Entity\User;

// Create a new user.
$user = User::create([
  'name' => 'username',
  'mail' => 'email@example.com',
  'pass' => 'password',
  'status' => 1,
  'roles' => ['authenticated'],
]);

// Save the user.
$user->save();

2. Try logging in with the newly created user info

💬 Support request
Status

Closed: outdated

Version

9.5

Component
User system  →

Last updated about 12 hours ago

Created by

🇶🇦Qatar abahmed

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024