We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38417
    • 92 Posts
    Momentary I am using a member login on an other site. Is it possible to import that datebase in the datebase of a new modx site with login, so the members do not have to register again?

    Ad.
      • 3749
      • 24,544 Posts
      I don't think so. The password hash method is almost certainly different. You could import the users and write a snippet that would set all the user passwords to something like username123, then tell the users to log in and reset their own passwords (though the site wouldn't be very secure until they did).


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 38417
        • 92 Posts
        Thanks BobRay,

        I will let them register again.
          • 28120
          • 380 Posts
          I might need this in a couple of projects.

          Is it not possible (I've tried but can't see it) to see how the login.register snippet is hashing the password?

          Is it possible to specify your own salt?
            • 4172
            • 5,888 Posts
            you may create an extended user-class.
            This class is using the old pw-hashing from imported users as long as the password wasn't changed.
            As soon, as the user gets a new password the default modx-hashing is used.

            <?php
            
            class pmUser extends modUser {
                function __construct(xPDO & $xpdo) {
                    parent::__construct($xpdo);
                    $this->set('class_key', 'pmUser');
                }
            
                /**
                 * Determines if the provided password matches the hashed password stored for the user.
                 *
                 * @param string $password The password to determine if it matches.
                 * @param array $options Optional settings for the hashing process.
                 * @return boolean True if the provided password matches the stored password for the user.
                 */
                public function passwordMatches($password, array $options = array()) {
                    $match = false;
            
            
                    $hashedPassword = md5(addslashes($password) . "xxxxxxxxxxxxxxxx");//code from old system deleted
            
                    $_SESSION['hashings']['hashedpw'] = $hashedPassword;
                    $_SESSION['hashings']['thispw'] = $this->get('password');
            
                    $match = ($this->get('password') === $hashedPassword);
                    if (!$match && $this->xpdo->getService('hashing', 'hashing.modHashing')) {
                        $options = array_merge(array('salt' => $this->get('salt')), $options);
                        $hashedPassword = $this->xpdo->hashing->getHash('', $this->get('hash_class'))->hash($password, $options);
                        $match = ($this->get('password') === $hashedPassword);
                    }
            
                    return $match;
                }
            
            
                /**
                 * The modUser password field is hashed automatically, and prevent sudo from being set via mass-assignment
                 *
                 * {@inheritdoc}
                 */
                public function set($k, $v = null, $vType = '', $checkhash = true) {
                    if (!$this->getOption(xPDO::OPT_SETUP)) {
                        if ($k == 'sudo')
                            return false;
                    }
                    if ($checkhash && in_array($k, array('password', 'cachepwd')) && $this->xpdo->getService('hashing', 'hashing.modHashing')) {
                        if (!$this->get('salt')) {
                            $this->set('salt', md5(uniqid(rand(), true)));
                        }
                        $vOptions = array('salt' => $this->get('salt'));
                        $v = $this->xpdo->hashing->getHash('', $this->get('hash_class'))->hash($v, $vOptions);
                    }
                    return modPrincipal::set($k, $v, $vType);
                }
            
            }
            
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 28120
              • 380 Posts
              This looks great, thanks.