/** */ protected function _changePassword($user, $oldpass, $newpass) { if (isset($this->_params['vmailinc']) && is_readable($this->_params['vmailinc'])) { include $this->_params['vmailinc']; } else { throw new Passwd_Exception('vmail.inc not found! (' . $this->_params['vmailinc'] . ')'); } list($user, $domain) = explode('@', $user); $res = vchpass($domain, $oldpass, $user, $newpass); if ($res[0]) { throw new Passwd_Exception(_("Incorrect old password.")); } }
// Looping through the config string and hoping to find the domain name // and password. while (list($domain_name, $settings) = each($vmailmgr_domains)) { if ($settings[0] == $base_user) { break; } } $vm_passwd = $settings[1]; } // Couldn't find what's needed if (!$domain_name || !$vm_passwd) { sayError("Could not derive your domain name and password, possibly due to misconfiguration. Alert your admin!"); } /** Including the vmailmgr's PHP includes file. Read INSTALL. **/ include "vchpass/vmail.inc"; $result = vchpass($domain_name, $vm_passwd, $vmailmgr_username, $newpass); /** Returns 0 if successful **/ if ($result[0]) { sayError("Could not change password. The error returned by vmailmgr is: {$result['1']}."); } /** Now updating the cookie so we can keep interfacing with IMAP server ** without having to re-login **/ ereg("(^.*/)[^/]+/[^/]+/[^/]+\$", $PHP_SELF, $regs); //get out of plugins dir $base_uri = $regs[1]; setcookie("key", OneTimePadEncrypt($newpass, $onetimepad), 0, $base_uri); doMyHeader(); echo "<p align='center'>" . _("Password changed successfully") . "</p>"; } /** That's all, folks. Now, if you STILL haven't read SECURITY, do so
/** * function that calls required vmail.inc functions and returns error codes. * * Information about vmailmgr return codes. * vmailmgr functions return array with two keys. * Array( * [0] => error code, integer (0=no error) * [1] => error message, string * ) * @return array */ function cpw_vmailmgrd_passwd($user, $domain, $oldpass, $newpass) { global $vmail_inc_path; // variable should be checked by cpw_vmailmgrd_init function include_once $vmail_inc_path; return vchpass($domain, $oldpass, $user, $newpass); }