/**
  * Method to bind an associative array of data to a user object
  *
  * @param   array  &$array  The associative array to bind to the object
  *
  * @return  boolean  True on success
  *
  * @since   11.1
  */
 public function bind(&$array)
 {
     // Let's check to see if the user is new or not
     if (empty($this->id)) {
         // Check the password and create the crypted password
         if (empty($array['password'])) {
             $array['password'] = Helper::genRandomPassword();
             $array['password2'] = $array['password'];
         }
         // Not all controllers check the password, although they should.
         // Hence this code is required:
         if (isset($array['password2']) && $array['password'] != $array['password2']) {
             $this->setError(Text::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
             return false;
         }
         $this->password_clear = ArrayHelper::getValue($array, 'password', '', 'string');
         $salt = Helper::genRandomPassword(32);
         $crypt = Helper::getCryptedPassword($array['password'], $salt);
         $array['password'] = $crypt . ':' . $salt;
         // Set the registration timestamp
         $this->set('registerDate', Factory::getDate()->toSql());
     } else {
         // Updating an existing user
         if (!empty($array['password'])) {
             if ($array['password'] != $array['password2']) {
                 $this->setError(Text::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'));
                 return false;
             }
             $this->password_clear = ArrayHelper::getValue($array, 'password', '', 'string');
             $salt = Helper::genRandomPassword(32);
             $crypt = Helper::getCryptedPassword($array['password'], $salt);
             $array['password'] = $crypt . ':' . $salt;
         } else {
             $array['password'] = $this->password;
         }
     }
     if (array_key_exists('params', $array)) {
         $params = '';
         $this->_params->loadArray($array['params']);
         if (is_array($array['params'])) {
             $params = (string) $this->_params;
         } else {
             $params = $array['params'];
         }
         $this->params = $params;
     }
     // Bind the array
     if (!$this->setProperties($array)) {
         $this->setError(Text::_('JLIB_USER_ERROR_BIND_ARRAY'));
         return false;
     }
     // Check that username is not greater than 150 characters
     $username = $this->get('username');
     if (strlen($username) > 150) {
         $username = substr($username, 0, 150);
         $this->set('username', $username);
     }
     // Check that password is not greater than 100 characters
     $password = $this->get('password');
     if (strlen($password) > 100) {
         $password = substr($password, 0, 100);
         $this->set('password', $password);
     }
     // Make sure its an integer
     $this->id = (int) $this->id;
     return true;
 }
 /**
  * Gets the user profile information
  *
  * @param   integer  $userId  The id of the user.
  *
  * @return  object
  *
  * @since   11.1
  */
 public static function getProfile($userId = 0)
 {
     if ($userId == 0) {
         $user = Factory::getUser();
         $userId = $user->id;
     }
     // Get the dispatcher and load the user's plugins.
     $dispatcher = Dispatcher::getInstance();
     Helper::importPlugin('user');
     $data = new Object();
     $data->id = $userId;
     // Trigger the data preparation event.
     $dispatcher->trigger('onContentPrepareData', array('com_users.profile', &$data));
     return $data;
 }