We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37152
    • 12 Posts
    Need help with API modX Revo create a user with a preset password (preferably in MD5, because it's all done to synchronize the users from another system).

    Create a user using the API described in this topic http://forums.modx.com/index.php?topic=59645.0 - works successfully. But the issue with the password still remains open. The proposed $user->set('password', md5 ('somePassword'));, of the same theme, does not work.

    There is a method $modx->changePassword('b33r4me', 'boo123'), but I just do not fit (it is necessary to set a password and preferably in a md5).

    The second day of dig API modX and can not find what I need. I do not want to bypass the API to modify the database directly, yes, and hashes in the database modX, does not seem like md5.

    Who faced a similar problem? Thanks in advance for any advice.

    P.S. Sorry for my English.
    • In MODX 2.1, we use PBKDF2 to hash the passwords with a random user-specific salt by default. You can set the hash_class to hashing.modMD5 to use MD5 passwords, but you will not be able to set those with
      $user->set('password', md5('password'));
      because that will hash your already hashed password. If you need to set raw values and bypass the behavior of set() in this case, you can use:
      $user->fromArray(array('password' => $alreadyMD5HashedPassword), '', false, true);
      with the $rawValues parameter set to true.
        • 37152
        • 12 Posts
        Thank you! Thanks to your advice I managed to make the synchronization of users.

        I would like in addition to the automatic authentication by sending ajax-request (username and password md5-hash) for authorization in the other system (modx.sample.com - modx, sample.com - my system).

        Now I study method modX::runProcessor(). It seems it can be to do what I had in mind.

        I would be glad to hear your competent opinion on the matter.
          • 37152
          • 12 Posts
          Solved the problem of sending ajxa-authorization request to a server-based (another system) immediately after successful authentication. To do so, created a special resource to the site and wrote to him the following snippet:

          Snippet Autologin (callback for JSONP):
          if (isset($_GET['email']) AND $_GET['password'])
          {
              $c = array(
                          'login_context' => 'web',
                          'add_contexts' => '',
                          'username' => $_GET['email'],
                          'password' => $_GET['password'],
                          'returnUrl' => '/forum/',
                          'rememberme' => ''
                       );
          
              echo $_GET['callback'] . '(' . $modx->runProcessor('security/login', $c) . ');';
          }