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

Comments

abahmed created an issue. See original summary.

chi’s picture

Status: Active » Postponed (maintainer needs more info)

This needs steps to reproduce.

cilefen’s picture

Category: Bug report » Support request
cilefen’s picture

enaznin’s picture

Issue summary: View changes

Updated the IS.

enaznin’s picture

Status: Postponed (maintainer needs more info) » Active

Updated the IS

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)

I cannot reproduce this. Your code works.

I put it in a file named test.php and executed it like vendor/bin/drush php:script test.php. The user can log in.

shiv_sharma’s picture

Not able to reproduce this issue.
Tried with two ways.
1. Added the code on submit handler its created the user and able to access the site with same credentials.
2. From DevelPHP just execute your code work fine here too.

Could you explain your issue which can help us to explore more..

cilefen’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

There reporter has not replied.