git subrepo commit (merge) mailcow/src/mailcow-dockerized

subrepo: subdir:   "mailcow/src/mailcow-dockerized"
  merged:   "02ae5285"
upstream: origin:   "https://github.com/mailcow/mailcow-dockerized.git"
  branch:   "master"
  commit:   "649a5c01"
git-subrepo: version:  "0.4.3"
  origin:   "???"
  commit:   "???"
Change-Id: I870ad468fba026cc5abf3c5699ed1e12ff28b32b
diff --git a/mailcow/src/mailcow-dockerized/data/web/inc/functions.domain_admin.inc.php b/mailcow/src/mailcow-dockerized/data/web/inc/functions.domain_admin.inc.php
index 206b371..804c0f8 100644
--- a/mailcow/src/mailcow-dockerized/data/web/inc/functions.domain_admin.inc.php
+++ b/mailcow/src/mailcow-dockerized/data/web/inc/functions.domain_admin.inc.php
@@ -65,61 +65,38 @@
           return false;

         }

       }

-      if (!empty($password) && !empty($password2)) {

-        if (!preg_match('/' . $GLOBALS['PASSWD_REGEP'] . '/', $password)) {

-          $_SESSION['return'][] = array(

-            'type' => 'danger',

-            'log' => array(__FUNCTION__, $_action, $_data_log),

-            'msg' => 'password_complexity'

-          );

-          return false;

-        }

-        if ($password != $password2) {

-          $_SESSION['return'][] = array(

-            'type' => 'danger',

-            'log' => array(__FUNCTION__, $_action, $_data_log),

-            'msg' => 'password_mismatch'

-          );

-          return false;

-        }

-        $password_hashed = hash_password($password);

-        $valid_domains = 0;

-        foreach ($domains as $domain) {

-          if (!is_valid_domain_name($domain) || mailbox('get', 'domain_details', $domain) === false) {

-            $_SESSION['return'][] = array(

-              'type' => 'danger',

-              'log' => array(__FUNCTION__, $_action, $_data_log),

-              'msg' => array('domain_invalid', htmlspecialchars($domain))

-            );

-            continue;

-          }

-          $valid_domains++;

-          $stmt = $pdo->prepare("INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)

-              VALUES (:username, :domain, :created, :active)");

-          $stmt->execute(array(

-            ':username' => $username,

-            ':domain' => $domain,

-            ':created' => date('Y-m-d H:i:s'),

-            ':active' => $active

-          ));

-        }

-        if ($valid_domains != 0) {

-          $stmt = $pdo->prepare("INSERT INTO `admin` (`username`, `password`, `superadmin`, `active`)

-            VALUES (:username, :password_hashed, '0', :active)");

-          $stmt->execute(array(

-            ':username' => $username,

-            ':password_hashed' => $password_hashed,

-            ':active' => $active

-          ));

-        }

+      if (password_check($password, $password2) !== true) {

+        continue;

       }

-      else {

-        $_SESSION['return'][] = array(

-          'type' => 'danger',

-          'log' => array(__FUNCTION__, $_action, $_data_log),

-          'msg' => 'password_empty'

-        );

-        return false;

+      $password_hashed = hash_password($password);

+      $valid_domains = 0;

+      foreach ($domains as $domain) {

+        if (!is_valid_domain_name($domain) || mailbox('get', 'domain_details', $domain) === false) {

+          $_SESSION['return'][] = array(

+            'type' => 'danger',

+            'log' => array(__FUNCTION__, $_action, $_data_log),

+            'msg' => array('domain_invalid', htmlspecialchars($domain))

+          );

+          continue;

+        }

+        $valid_domains++;

+        $stmt = $pdo->prepare("INSERT INTO `domain_admins` (`username`, `domain`, `created`, `active`)

+            VALUES (:username, :domain, :created, :active)");

+        $stmt->execute(array(

+          ':username' => $username,

+          ':domain' => $domain,

+          ':created' => date('Y-m-d H:i:s'),

+          ':active' => $active

+        ));

+      }

+      if ($valid_domains != 0) {

+        $stmt = $pdo->prepare("INSERT INTO `admin` (`username`, `password`, `superadmin`, `active`)

+          VALUES (:username, :password_hashed, '0', :active)");

+        $stmt->execute(array(

+          ':username' => $username,

+          ':password_hashed' => $password_hashed,

+          ':active' => $active

+        ));

       }

       $stmt = $pdo->prepare("INSERT INTO `da_acl` (`username`) VALUES (:username)");

       $stmt->execute(array(

@@ -218,22 +195,9 @@
               ));

             }

           }

-          if (!empty($password) && !empty($password2)) {

-            if (!preg_match('/' . $GLOBALS['PASSWD_REGEP'] . '/', $password)) {

-              $_SESSION['return'][] = array(

-                'type' => 'danger',

-                'log' => array(__FUNCTION__, $_action, $_data_log),

-                'msg' => 'password_complexity'

-              );

-              continue;

-            }

-            if ($password != $password2) {

-              $_SESSION['return'][] = array(

-                'type' => 'danger',

-                'log' => array(__FUNCTION__, $_action, $_data_log),

-                'msg' => 'password_mismatch'

-              );

-              continue;

+          if (!empty($password)) {

+            if (password_check($password, $password2) !== true) {

+              return false;

             }

             $password_hashed = hash_password($password);

             $stmt = $pdo->prepare("UPDATE `admin` SET `username` = :username_new, `active` = :active, `password` = :password_hashed WHERE `username` = :username");

@@ -296,30 +260,15 @@
           );

           return false;

         }

-        if (!empty($password_new2) && !empty($password_new)) {

-          if ($password_new2 != $password_new) {

-            $_SESSION['return'][] = array(

-              'type' => 'danger',

-              'log' => array(__FUNCTION__, $_action, $_data_log),

-              'msg' => 'password_mismatch'

-            );

-            return false;

-          }

-          if (!preg_match('/' . $GLOBALS['PASSWD_REGEP'] . '/', $password_new)) {

-            $_SESSION['return'][] = array(

-              'type' => 'danger',

-              'log' => array(__FUNCTION__, $_action, $_data_log),

-              'msg' => 'password_complexity'

-            );

-            return false;

-          }

-          $password_hashed = hash_password($password_new);

-          $stmt = $pdo->prepare("UPDATE `admin` SET `password` = :password_hashed WHERE `username` = :username");

-          $stmt->execute(array(

-            ':password_hashed' => $password_hashed,

-            ':username' => $username

-          ));

+        if (password_check($password_new, $password_new2) !== true) {

+          return false;

         }

+        $password_hashed = hash_password($password_new);

+        $stmt = $pdo->prepare("UPDATE `admin` SET `password` = :password_hashed WHERE `username` = :username");

+        $stmt->execute(array(

+          ':password_hashed' => $password_hashed,

+          ':username' => $username

+        ));

         $_SESSION['return'][] = array(

           'type' => 'success',

           'log' => array(__FUNCTION__, $_action, $_data_log),