We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6059
    • 45 Posts
    How can i set the password from a snippet for a user?

    i tried getObject(’modUser’, ...) then save()

    and it set a new password but it is not md5 format. i tried a clean password without encryption and with encryption but the saved password looks not like md5 and i can not use it to login.
      • 22303 MODX Staff
      • 10,725 Posts
      Passwords are stored using a configurable hashing algorithm in MODX Revolution 2.1+. Any legacy users created in 2.0.x deployments that have been upgraded to 2.1 will have modMD5 as the hash_class while new users created in 2.1 will by default use modPBKDF2. Regardless of which hash_class a user has, you can easily set the password...

      <?php
      $user = $modx->getObject('modUser', array('username' => 'TED'));
      if ($user) {
          $user->set('password', 'thisismypassword!');
          $user->save();
      }
      


      and it will automatically be hashed using the hash_class specified for the user.