Jump to main content Jump to doc navigation

modUser::changePassword

Changes the password of a user. It first matches the oldPassword you specify to the current password using modUser->passwordMatches($oldPassword), then sets the password and finally it invokes the OnUserChangePassword event. Returns true if the password was changed, false if not.

Syntax

API Doc: http://api.modx.com/revolution/2.2/db_core_model_modx_moduser.class.html#%5CmodUser::changePassword()

boolean changePassword (string $newPassword, string $oldPassword)

Example

Change the password of the user 'foobar' from 'boo123' to 'b33r4me'

$user = $modx->getObject('modUser',array('username' => 'foobar'));
$user->changePassword('b33r4me', 'boo123');

Change the password of the user currently logged in from 'mypass' to 's3cur3d'.

$modx->user->changePassword('s3cur3d','mypass');

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • Chris Fickling
  • CrewMark
  • deJaya
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$301 per month—let's make that $500!

Learn more