I know that in Drupal 7 I could reset the user #1 password via code.
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/includes/password.inc';
$newhash = user_hash_password('newpass');
$updatepass = db_update('users')
->fields(array('pass' => $newhash))
->condition('uid', '1', '=')
->execute();
(user_hash_password()
doesn't exist anymore in Drupal 8.)
Alternatively, I could use the following code.
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/includes/password.inc';
$edit['pass'] = 'newpass';
$account= user_load(1);
user_save($account, $edit);
What is the equivalent code for Drupal 8? What API should I use for this purpose?