Skip to content

Instantly share code, notes, and snippets.

@eguicciardi
Last active February 22, 2017 21:46
Show Gist options
  • Save eguicciardi/7fbbd9caddcdff92f5f1f7fea1d9d335 to your computer and use it in GitHub Desktop.
Save eguicciardi/7fbbd9caddcdff92f5f1f7fea1d9d335 to your computer and use it in GitHub Desktop.
Function to reset a user's password
<?php
function password_reset(){
global $user;
$hashthepass = 'password'; /* Your password value*/
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$hashthepass = user_hash_password(trim($hashthepass));
if (!$hashthepass) {
return FALSE;
} else {
db_update('users')
->fields(array(
'pass' => $hashthepass
))
->condition('uid', $user->uid)
->execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment