Page 1 of 1

Changing a user password programmatically

Posted: Wed Nov 09, 2016 8:48 am
by davecov
This changes the password in the database:

Code: Select all

  $query="UPDATE jos_users SET password='".MD5('$pass')."' WHERE username='".$user."' ";
  $db->setQuery( $query );
  $db->query();
.. but the user cannot log in.

This:

Code: Select all

  $userObj = JFactory::getUser($this->GetIdByUserName($user));
  $password = array('password' => $pass, 'password2' => $pass);
  $userObj->bind($password));
  $userObj->save();
gives me a server 500 error.

Anyone know how to achieve this?

The site runs Joomla 1.5.26

Re: Changing a user password programmatically

Posted: Wed Nov 09, 2016 11:56 am
by davecov
Ok, here's how to do it:

Code: Select all

  $userObj = JFactory::getUser($userID);
  $password = array('password' => $pass, 'password2' => $pass);
  $userObj->bind($password));
  $userObj->save();
Find the $userID of the user account you want to access and get the user object with getUser.
Bind the $userObj with the password array as defined above.
Save the $userObj.

Simpler than Donald Trump!