if ($oldpw) {
         $oldpw = StripeGate\Utils::unfusc($oldpw);
     }
     $newpw = trim($params['masterpass']);
     if ($oldpw != $newpw) {
         //update all data which uses current password
         $pre = cms_db_prefix();
         $sql = 'SELECT account_id,privtoken,testprivtoken FROM ' . $pre . 'module_sgt_account';
         $rst = $db->Execute($sql);
         if ($rst) {
             $sql = 'UPDATE ' . $pre . 'module_sgt_account SET privtoken=?,testprivtoken=? WHERE account_id=?';
             while (!$rst->EOF) {
                 $t = StripeGate\Utils::decrypt_value($mod, $rst->fields[1], $oldpw);
                 $t = $newpw ? StripeGate\Utils::encrypt_value($mod, $t, $newpw) : StripeGate\Utils::fusc($t);
                 $t2 = StripeGate\Utils::decrypt_value($mod, $rst->fields[2], $oldpw);
                 $t2 = $newpw ? StripeGate\Utils::encrypt_value($mod, $t2, $newpw) : StripeGate\Utils::fusc($t2);
                 $db->Execute($sql, array($t, $t2, $rst->fields[0]));
                 if (!$rst->MoveNext()) {
                     break;
                 }
             }
             $rst->Close();
         }
         //TODO if record-table data is encrypted
         if ($newpw) {
             $newpw = StripeGate\Utils::fusc($newpw);
         }
         $this->SetPreference('masterpass', $newpw);
     }
 }
 $params['activetab'] = 'settings';
# Refer to licence and other details at the top of file StripeGate.module.php
# More info at http://dev.cmsmadesimple.org/projects/stripegate
#----------------------------------------------------------------------
$pmod = $this->CheckPermission('ModifyStripeGateProperties') || $this->CheckPermission('ModifyStripeAccount');
$puse = $this->CheckPermission('UseStripeAccount');
if (!($pmod || $puse)) {
    exit;
}
if (isset($params['cancel'])) {
    $this->Redirect($id, 'defaultadmin');
}
$pref = cms_db_prefix();
if (isset($params['submit']) && $pmod) {
    $alias = StripeGate\Utils::ConstructAlias($params['alias'], $params['name']);
    $privatetoken = $params['privtoken'] ? StripeGate\Utils::encrypt_value($this, $params['privtoken']) : '';
    $privatetesttoken = $params['testprivtoken'] ? StripeGate\Utils::encrypt_value($this, $params['testprivtoken']) : '';
    if (strpos($params['surchargerate'], '%') !== FALSE) {
        $sur = str_replace('%', '', $params['surchargerate']);
        $sur = (double) $sur / 100.0;
    } else {
        $sur = $params['surchargerate'] + 0.0;
    }
    $test = !empty($params['usetest']);
    $default = !empty($params['isdefault']);
    if ($default) {
        //clear old default
        $db->Execute('UPDATE ' . $pref . 'module_sgt_account SET isdefault=FALSE WHERE isdefault=TRUE');
    }
    $active = !empty($params['isactive']);
    $fmt = trim($params['amountformat']);
    if (!$fmt || !preg_match('/^(.*)?S(\\W+)?(\\d*)$/', $fmt)) {