Programmatically change the user's password

Last updated on 03/11/2017

Method 1: Pure Drupal API

$user = \Drupal\user\Entity\User::load($uid);
$user->setPassword('newpassword');
$user->save();

Method 2: Drush:

$ drush upwd 1 --password="newpassword"

Method 3: Drupal Console:

$ drupal user:password:reset