Example #1
0
 public function chPasswd($password)
 {
     $hook = new Hook($this->ampdb, 'ampoliros', 'site.chpasswd');
     if ($hook->CallHooks('calltime', $this, array('password' => $password)) == HOOK_RESULT_OK) {
         if (strlen($password) and $this->siteserial) {
             // We may require old password if superuser password cannot be changed
             //
             $sitequery =& $this->ampdb->Execute('SELECT sitepassword ' . 'FROM sites ' . 'WHERE id=' . (int) $this->siteserial);
             // Changes site password
             //
             if ($this->ampdb->Execute('UPDATE sites ' . 'SET sitepassword='******' ' . 'WHERE id=' . (int) $this->siteserial)) {
                 // Changes site superuser password
                 //
                 $tmpuser = new User($this->ampdb, $this->siteserial);
                 $tmpuser->SetUserIDByUserName($this->siteid);
                 $userdata = $tmpuser->GetUserData();
                 $qres = $this->ampdb->Execute('UPDATE users SET password = '******' WHERE id=' . (int) $userdata[id]);
                 if ($qres) {
                     if ($hook->CallHooks('passwordchanged', $this, array('password' => $password)) == HOOK_RESULT_OK) {
                         return true;
                     }
                 } else {
                     // Fallback to old site password
                     //
                     $this->ampdb->Execute('UPDATE sites ' . 'SET sitepassword='******'sitepassword')) . ' ' . 'WHERE id=' . (int) $this->siteserial);
                     $this->sitelog->LogEvent($this->siteid, 'Unable to change password for user ' . $this->siteid . '; restored old site password', LOGGER_ERROR);
                 }
             } else {
                 $this->sitelog->LogEvent($this->siteid, 'Unable to change site password', LOGGER_ERROR);
             }
         } else {
             if (!strlen($password)) {
                 $this->sitelog->LogEvent($this->siteid, 'Empty password', LOGGER_ERROR);
             }
             if (!$this->siteserial) {
                 $this->sitelog->LogEvent($this->siteid, 'Empty site serial', LOGGER_ERROR);
             }
         }
     }
     return false;
 }