Ver Fonte

add server side password check

andre há 5 anos atrás
pai
commit
1f1282925b
1 ficheiros alterados com 37 adições e 0 exclusões
  1. 37 0
      zimbraSingle.php

+ 37 - 0
zimbraSingle.php

@@ -48,6 +48,39 @@ function zimbraSingleFindAll($haystack, $needle)
     return $values;
 }
 
+/**
+ * server side password check
+ * 
+ * recheck the client side password check
+ * in case that the client side check has been disabled
+ * 
+ * @param string $pwd password
+ * 
+ * @return string missing features or null if the password matches our needs
+ */
+function zimbraSingleCheckPassword($pwd) {
+    if (strlen($pwd) < 8) {
+        return 'Das das Passwort ist zu kurz. Es werden mind. 8 Zeichen benötigt';
+    }
+
+    if (!preg_match('#[0-9]+#', $pwd)) {
+        return 'Das Passwort muss mindestens eine Zahl enthalten';
+    }
+
+    if (!preg_match('#[A-Z]+#', $pwd)) {
+        return 'Das Passwort muss mindestens einen Grossbuchstaben (A-Z) enthalten';
+    }     
+
+    if (!preg_match('#[a-z]+#', $pwd)) {
+        return 'Das Passwort muss mindestens einen Kleinbuchstaben (a-z) enthalten';
+    }     
+
+    if (!preg_match('#[^\w]+#', $pwd)) {
+        return 'Das Passwort muss mindestens ein Sonderzeichen (.,-:=) enthalten';
+    }
+    return null;
+}
+
 /**
  * Define module related meta data.
  *
@@ -264,6 +297,10 @@ function zimbraSingle_UsageUpdate($params) {
  * @return string 'success' or an error message
  */
 function zimbraSingle_ChangePassword($params) {
+	$checkPassword = zimbraSingleCheckPassword($params['password']);
+	if ($checkPassword != null) {
+	    return $checkPassword;
+	}
     $api = new Zm_Auth($params['serverhostname'], $params['serverusername'], $params['serverpassword'], 'admin');
     $login = $api->login();
     if(is_a($login, 'Exception')) {