Source for file DBMS_FIELD_PASSWORD.phpclass

Documentation is available at DBMS_FIELD_PASSWORD.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_PASSWORD.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   string
  8.   *
  9.   * @author     Peter Krebs <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2005 by LVUS <http://opencsp.lvu.at>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @version pk-05-02-16
  14.   *
  15.   ***/
  16.  
  17. if (empty($GLOBALS['OCSP']['DBMSFLD_PATH'])) $GLOBALS['OCSP']['DBMSFLD_PATH']=dirname(__FILE__)."/";
  18. if (!class_exists("DBMS_FIELD")) {
  19.     require_once dirname(__FILE__)."/DBMS_FIELD.phpclass";
  20. }
  21.  
  22. /**
  23.   * Class DBMS_FIELD_PASSWORD
  24.   *
  25.   * @project    Open CSP-Management
  26.   * @package    dbms_field
  27.   * @category   string
  28.   *
  29.   * @author     Peter Krebs <p.krebs@lvus.at>
  30.   * @copyright  (c) 2002-2005 by LVUS <http://opencsp.lvu.at>
  31.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   * @todo editform no search
  34.   * @todo only mysql PASSWORD("...") is supported now add MD5
  35.   *
  36.   ***/
  37. class DBMS_FIELD_PASSWORD extends DBMS_FIELD {
  38.     var $className     = "Password";
  39.  
  40.     var $maxlength     = 16;
  41.     var $size          = 16;
  42.     var $noMatchErrMsg = "Die beiden Passworteingaben stimmen nicht überein.";
  43.  
  44.     /**
  45.       * @var int $pwdMinSize min required size
  46.       * @since pk-05-02-22
  47.       ***/
  48.     var $pwdMinSize     = 4;
  49.  
  50.     /**
  51.       * @var int $pwdSizeErrMsg 
  52.       * @since pk-05-02-22
  53.       ***/
  54.     var $pwdSizeErrMsg = "Ihr Passwort ist muss mindestens \$*pwdMinSize\$ Zeichen haben";
  55.  
  56.  
  57.     /**
  58.       * source file of the class
  59.       *
  60.       * @var string $classSrcFile 
  61.       * @since pk-05-02-16
  62.       ***/
  63.     var $classSrcFile=__FILE__;
  64.  
  65.     /**
  66.       * @var string $sqlFunction the sql function to use creating the password
  67.       * @since pk-06-12-06
  68.       ***/
  69.     var $sqlFunction="PASSWORD";
  70.  
  71.     /**
  72.       * @var array $sqlFunctLst a list of available sql functions to use
  73.       * @since pk-06-12-06
  74.       * @todo ensure each DB module can deal with it
  75.       ***/
  76.     var $sqlFunctLst=array(
  77.         'ASSIS'         =>"keine Umwandlung",
  78.         'PASSWORD'      =>"password('PASSWD')",
  79.         'ENCRYPT'       =>"encrypt('PASSWD')",
  80.         'MD5'           =>"md5('PASSWD')",
  81.         'OLD_PASSWORD'  =>"old_password('PASSWORD')",
  82.     );
  83.  
  84.     /**
  85.       * @var boolean $allowCryptInput the user can input the password in encrypted form no changes are made
  86.       * @since pk-06-12-06
  87.       ***/
  88.     var $allowCryptInput=FALSE;
  89.  
  90.     // ###########################################################
  91.     // FIELD DEFINITION DATA METHODS
  92.     // ###########################################################
  93.  
  94.     /**
  95.       * returns an array of field to bie shown in the edit form
  96.       * by using editTbl_echoForm
  97.       *
  98.       * the array is in the form:
  99.       *
  100.       * <code>
  101.       * [_sectionName_]
  102.       *      [TITLE] -> string
  103.       *      [_rowName_]
  104.       *         [FLDLAB]  (complete html code without <td></td>)
  105.       *         [FLDVAL] (complete html code without <td></td>)
  106.       * </code>
  107.       *
  108.       * @param boolean $debug 
  109.       *
  110.       * @returns array
  111.       *
  112.       * @since pk-06-09-18
  113.       * @version pk-08-06-04
  114.       */
  115.     function editTbl_getFieldEditArr($debug=False{
  116.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_INT::editTbl_getFieldEditArr","",0);
  117.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  118.  
  119.         unset($a_ret['LIST']);
  120.         
  121.            include __OCSP_PHPINCPATH__ "db" _OCSP_DIRSEP_ "forms" _OCSP_DIRSEP_ "languages" _OCSP_DIRSEP_ "DBMS_FIELD_PASSWORD_FieldEditArr.de.phpinc";
  122.         
  123.         return $a_ret;
  124.     }
  125.  
  126.     /**
  127.       * saves the form desc
  128.       *
  129.       * @returns boolean
  130.       *
  131.       * @version pk-04-10-12
  132.       *
  133.       ***/
  134.     function save({
  135.         $ret parent::save();
  136.  
  137.         $this->pwdMinSize       =intval($_POST['pwdMinSize']);
  138.         $this->pwdSizeErrMsg    =$_POST['pwdSizeErrMsg'];
  139.         $this->noMatchErrMsg    =$_POST['noMatchErrMsg'];
  140.         $this->sqlFunction      =$_POST['sqlFunction'];
  141.         $this->allowCryptInput  =((isset($_POST['allowCryptInput']&& intval($_POST['allowCryptInput'])) TRUE FALSE);
  142.  
  143.         $this->showInList        = False;
  144.         
  145.         return $ret;
  146.     }
  147.  
  148.     /**
  149.       * returns the html code for a editable formular element
  150.       *
  151.       * @param mixed $aValue the value to set
  152.       * @param string $arrName 
  153.       * @param string $nameAdd  append something to name like "[VALUE]" for search forms
  154.       *
  155.       * @return string 
  156.       *
  157.       * @since pk-05-02-18
  158.       *
  159.       ***/
  160.     function getInputTag($aValue,$arrName="DBVAL",$nameAdd="",$debug=FALSE{
  161.         if ($debugecho "<p><b>DBMS_FIELD_PASSWORD::getInputTag(...)</b> (".get_class($this)."/".$this->myName.")</p>";
  162.         $tag  "<input ";
  163.         $tag .= "name=\"".$arrName."[".$this->myName."][1]".$nameAdd."\" ";
  164.         $tag .= "value=\"".htmlspecialchars($aValue)."\" "/* <pk-05-01-06 /> */
  165.         $tag .= "size=\"".$this->size."\" maxlength=\"".$this->maxlength."\" ";
  166.         $tag .= "type=\"password\" ";
  167.         if ($this->tabIndex$tag.="tabindex=\"".$this->tabIndex."\" ";
  168.         $tag .= "><br \>";
  169.         $tag .= "<input ";
  170.         $tag .= "name=\"".$arrName."[".$this->myName."][2]".$nameAdd."\" ";
  171.         $tag .= "value=\"".htmlspecialchars($aValue)."\" "/* <pk-05-01-06 /> */
  172.         $tag .= "size=\"".$this->size."\" maxlength=\"".$this->maxlength."\" ";
  173.         $tag .= "type=\"password\" ";
  174.         if ($this->tabIndex$tag.="tabindex=\"".$this->tabIndex."\" ";
  175.         $tag .= ">";
  176.         return $tag;
  177.     }
  178.  
  179.     function getScreenValue($aValue,$arrName,$debug{
  180.         return "********";
  181.     }
  182.  
  183.     /**
  184.       * returns the field value if the two fields matches
  185.       *
  186.       * NOTE this returns the clear text password you have
  187.       * to encrypt it before saving it to the database
  188.       *
  189.       * @param  string  $aValue     the value
  190.       * @param  array   $err        error array
  191.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  192.       * @param  bool    $debug 
  193.       *
  194.       * @return string 
  195.       *
  196.       * @since   pk-03-12-13
  197.       * @version pk-03-12-13
  198.       * @version pk-05-06-17
  199.       *
  200.       ***/
  201.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=False{
  202.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_PASSWORD::getValue($aValue)");
  203.         if (is_array($aValue)) // <pk-05-06-17 removed && (!empty($aValue[1]))) {
  204.             if (strlen($aValue[1]$this->pwdMinSize{
  205.                 $err['ERROR']=True;
  206.                 $err[$this->myName]['MSG']=str_replace("\$*pwdMinSize\$",$this->pwdMinSize,$this->pwdSizeErrMsg);
  207.                 $err[$this->myName]['LABEL']=$this->label;
  208.                 return NULL;
  209.             }
  210.             if ($aValue[1== $aValue[2]{
  211.                 switch($this->sqlFunction)
  212.                 {
  213.                     case 'MD5':
  214.                         return md5($aValue[1]);
  215.                     case 'ASSIS'
  216.                         return $aValue[1];
  217.                     default:
  218.                         $obj_db $this->myForm->getDBObj();
  219.                         $str_query "SELECT " $this->sqlFunction . "(" $obj_db->qs_getSlashedValue($aValue[1].") FROM DUAL";
  220.                         if ($str_ret $obj_db->getOne($str_query))
  221.                         {
  222.                             return $str_ret;
  223.                         else {
  224.                             throw new Exception(_OCSP_EXCEP_QUERYFAILED_ ":" $str_query);
  225.                         }
  226.                         
  227.                         break;
  228.                 }
  229.             else {
  230.                 $err['ERROR']=True;
  231.                 $err[$this->myName]['MSG']=$this->noMatchErrMsg;
  232.                 $err[$this->myName]['LABEL']=$this->label;
  233.                 return Null;
  234.             }
  235.         else {
  236.             return Null;
  237.         }
  238.     }
  239.  
  240.     /**
  241.       * make a database command to store encrypted password
  242.       *
  243.       * NOTE mySQL only
  244.       *
  245.       * @param  string  $aValue     the value
  246.       * @param  array   $err        error array
  247.       * @param  string  $arrName    name of the global array to access field gloabl ${$arrName}
  248.       * @param  bool    $debug 
  249.       *
  250.       * @return string 
  251.       *
  252.       * @todo   currently mySQL only
  253.       *
  254.       ***/
  255.     function slashedValue($aValue,&$err{
  256.         if ((is_array($aValue)) && (!empty($aValue[1]))) {
  257.             if ($aValue[1== $aValue[2]{
  258.                 if (empty($this->sqlFunction)) return "PASSWORD(\"".addSlashes($aValue[1])."\")";
  259.                 return $this->sqlFunction."(".$GLOBALS['USRDB']->qs_getSlashedValue($aValue[1]).")";
  260.             else {
  261.                 $err['ERROR']=TRUE;
  262.                 $err[$this->myName]['MSG']="PASSWORD_NO_MATCH";
  263.                 $err[$this->myName]['LABEL']=$this->label;
  264.                 return NULL;
  265.             }
  266.         else {
  267.             return NULL;
  268.         }
  269.     }
  270.  
  271.     function getAssignment($aValue,&$err{
  272.         if ((is_array($aValue)) && (!empty($aValue[1]))) {
  273.            return $this->myName."=".$this->slashedValue($aValue,$err);
  274.         }
  275.     }
  276.  
  277. // end class DBMS_FIELD_PASSWORD
  278. ?>

Documentation generated on Thu, 08 Jan 2009 17:42:36 +0100 by phpDocumentor 1.4.0a2