I'm trying to create a custom module for resetting the user's password.
In the following block of code I'm attempting to get the password in hash form:
$pass='User123@';
$autoloader =require_once(\Drupal::service('file_system')->realpath('autoload.php'));
//echo $autoloader; exit;
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod', FALSE);
$kernel->boot();
$password_hasher = $kernel->getContainer()->get('password');
$newhash = $password_hasher->hash($pass);
//echo $newhash ; exit;
This is my db update code:
$updatepass = \Drupal::database()->update('users_field_data')
->fields(array(
'pass' => $newhash,
))
->condition('name', "$id",'=')
->execute();
Please help me understand what mistake I've made.