From e0208a456a03216778c8fb2d63ed8522bae7badd Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 27 Oct 2008 17:14:58 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSformRule=5Fpassword=20:=20Ajout=20d'une?= =?UTF-8?q?=20r=C3=A8gle=20pour=20v=C3=A9rifier=20un=20mot=20de=20passe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class/class.LSformRule_password.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 trunk/includes/class/class.LSformRule_password.php diff --git a/trunk/includes/class/class.LSformRule_password.php b/trunk/includes/class/class.LSformRule_password.php new file mode 100644 index 00000000..501792e6 --- /dev/null +++ b/trunk/includes/class/class.LSformRule_password.php @@ -0,0 +1,75 @@ + + */ +class LSformRule_password extends LSformRule { + + /** + * Vérification de la valeur. + * + * @param string $values Valeur à vérifier + * @param array $options Options de validation + * - 'minLength' : la longueur maximale + * - 'maxLength' : la longueur minimale + * - 'prohibitedValues' : Un tableau de valeurs interdites + * - 'regex' : une ou plusieurs expressions régulières + * devant matche + * @param object $formElement L'objet formElement attaché + * + * @return boolean true si la valeur est valide, false sinon + */ + function validate ($value,$options=array(),$formElement) { + if(isset($options['params']['maxLength'])) { + if (strlen($value)>$options['params']['maxLength']) + return; + } + + if(isset($options['params']['minLength'])) { + if (strlen($value)<$options['params']['minLength']) + return; + } + + if(isset($options['params']['regex'])) { + if (!is_array($options['params']['regex'])) { + $options['params']['regex']=array($options['params']['regex']); + } + foreach($options['params']['regex'] as $regex) { + if (!ereg($regex,$value)) + return; + } + } + + if(is_array($options['params']['prohibitedValues'])) { + if (in_array($value,$options['params']['prohibitedValues'])) + return; + } + + return true; + } + +} + +?>