Changing a user password programmatically

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
davecov
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Thu Mar 21, 2013 7:17 am

Changing a user password programmatically

Post by davecov » Wed Nov 09, 2016 8:48 am

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

davecov
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Thu Mar 21, 2013 7:17 am

Re: Changing a user password programmatically

Post by davecov » Wed Nov 09, 2016 11:56 am

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!


Locked

Return to “Joomla! 1.5 Coding”