From c397a4655346427074664c7f5c20588ff5804d33 Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Fri, 15 Nov 2019 15:59:54 +0100
Subject: [PATCH] FEAT #12162 TIME 0:30 generate random password

---
 src/app/user/models/UserModelAbstract.php | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/app/user/models/UserModelAbstract.php b/src/app/user/models/UserModelAbstract.php
index 2cec649bfe7..f6394028978 100755
--- a/src/app/user/models/UserModelAbstract.php
+++ b/src/app/user/models/UserModelAbstract.php
@@ -83,6 +83,14 @@ abstract class UserModelAbstract
         ValidatorModel::notEmpty($aArgs['user'], ['userId', 'firstname', 'lastname']);
         ValidatorModel::stringType($aArgs['user'], ['userId', 'firstname', 'lastname', 'mail', 'initials', 'phone', 'changePassword', 'loginmode']);
 
+        $length = rand(50, 70);
+        $chars = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz!@$%^*_=+,.?';
+        $count = mb_strlen($chars);
+        for ($i = 0, $password = ''; $i < $length; $i++) {
+            $index = rand(0, $count - 1);
+            $password .= mb_substr($chars, $index, 1);
+        }
+
         DatabaseModel::insert([
             'table'         => 'users',
             'columnsValues' => [
@@ -95,7 +103,7 @@ abstract class UserModelAbstract
                 'status'                        => 'OK',
                 'change_password'               => empty($aArgs['user']['changePassword']) ? 'Y' : $aArgs['user']['changePassword'],
                 'loginmode'                     => empty($aArgs['user']['loginmode']) ? 'standard' : $aArgs['user']['loginmode'],
-                'password'                      => AuthenticationModel::getPasswordHash('maarch'),
+                'password'                      => AuthenticationModel::getPasswordHash($password),
                 'password_modification_date'    => 'CURRENT_TIMESTAMP'
             ]
         ]);
-- 
GitLab