From 3a0bf96e925fc88a80788cfadf80be331cdacc3c Mon Sep 17 00:00:00 2001 From: Eric Seigne Date: Wed, 13 Mar 2024 11:49:03 +0100 Subject: [PATCH] add password and genericpassword entry types --- htdocs/core/class/html.formsetup.class.php | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/htdocs/core/class/html.formsetup.class.php b/htdocs/core/class/html.formsetup.class.php index e5199267d31..700a66d422a 100644 --- a/htdocs/core/class/html.formsetup.class.php +++ b/htdocs/core/class/html.formsetup.class.php @@ -905,6 +905,10 @@ class FormSetupItem $selected = (empty($this->fieldValue) ? '' : $this->fieldValue); $out.= $this->form->select_comptes($selected, $this->confKey, 0, '', 0, '', 0, '', 1); } + } elseif ($this->type == 'password') { + $out.= $this->generateInputFieldPassword('dolibarr'); + } elseif ($this->type == 'genericpassword') { + $out.= $this->generateInputFieldPassword('generic'); } else { $out.= $this->generateInputFieldText(); } @@ -1028,6 +1032,37 @@ class FormSetupItem } + /** + * generate input field for a password + * + * @param [type] $type 'dolibarr' (dolibarr password rules apply) or 'generic' + * + * @return string + */ + public function generateInputFieldPassword($type = 'generic') + { + global $conf, $langs, $user; + + $min = 8; + $max = 50; + if ($type == 'dolibarr') { + $gen = getDolGlobalString('USER_PASSWORD_GENERATED', 'standard'); + if ($gen == 'none') { + $gen = 'standard'; + } + $nomclass = "modGeneratePass".ucfirst($gen); + $nomfichier = $nomclass.".class.php"; + require_once DOL_DOCUMENT_ROOT."/core/modules/security/generate/".$nomfichier; + $genhandler = new $nomclass($this->db, $conf, $langs, $user); + $min = $genhandler->length; + $max = $genhandler->length2; + } + $out = ''; + return $out; + } + + + /** * generateInputFieldMultiSelect * @@ -1209,6 +1244,8 @@ class FormSetupItem } elseif ($resbank < 0) { $this->setErrors($bankaccount->errors); } + } elseif ($this->type == 'password' || $this->type == 'genericpassword') { + $out.= str_repeat('*', strlen($this->fieldValue)); } else { $out.= $this->fieldValue; } @@ -1480,4 +1517,28 @@ class FormSetupItem $this->type = 'selectBankAccount'; return $this; } + + /** + * Set type of input as a password with dolibarr password rules apply. + * Hide entry on display. + * + * @return self + */ + public function setAsPassword() + { + $this->type = 'password'; + return $this; + } + + /** + * Set type of input as a generic password without dolibarr password rules (for external passwords for example). + * Hide entry on display. + * + * @return self + */ + public function setAsGenericPassword() + { + $this->type = 'genericpassword'; + return $this; + } }