예제 #1
0
 /**
  * Sets username and password for person
  *
  * @param string $username Contains username
  * @param string $new_password Contains the new password to set
  */
 public function set_account($username, $new_password)
 {
     $this->_account = midcom_core_account::get($this->_person);
     if (!empty($new_password)) {
         $new_password_encrypted = midcom_connection::prepare_password($new_password);
         //check if the new encrypted password was already used
         if ($this->check_password_reuse($new_password_encrypted) && $this->check_password_strength($new_password)) {
             $this->_save_old_password();
             $this->_account->set_password($new_password);
         } else {
             $this->errstr = "password strength too low";
             return false;
         }
     }
     $this->_account->set_username($username);
     //probably username not unique
     if (!$this->_account->save()) {
         $this->errstr = "Failed to save account";
         return false;
     }
     if (!empty($new_password)) {
         //add timestamp of password-change
         $this->_person->set_parameter("org_openpsa_user_password", "last_change", time());
     }
     //sets privilege
     midcom::get('auth')->request_sudo($this->_component);
     $this->_person->set_privilege('midgard:owner', "user:" . $this->_person->guid);
     midcom::get('auth')->drop_sudo();
     return true;
 }