From 1e86f2d5fd9e9d54082cb96a1e9a72b1592bd581 Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 26 Jan 2019 21:21:28 +0100 Subject: [PATCH 1/2] Re-use password generator from ISPconfig core --- new_service.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/new_service.php b/new_service.php index ae944a5..ea8fe2d 100644 --- a/new_service.php +++ b/new_service.php @@ -115,6 +115,9 @@ class page_action extends tform_actions { // add domain $domain_id = $remote->insert_query('../client/form/domain.tform.php', $fields['client_id'], array('domain' => $fields['domain'])); + + $min_password_length = 8; + if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length']; // DNS Zone if($fields['dns']) @@ -357,7 +360,7 @@ class page_action extends tform_actions { // validate, on error skip if( ! preg_match('/^[_a-z0-9][\w\.\-_\+@]{1,63}$/', $mailbox)) continue; - $mailbox_passwords[$mailbox] = substr(sha1(rand()), 0, 10); + $mailbox_passwords[$mailbox] = $app->auth->get_random_password($min_password_length, true); $params = array( 'server_id' => $template['mail_server_id'], @@ -452,7 +455,7 @@ class page_action extends tform_actions { 'server_id' => $template['database_server_id'], 'database_user' => $client_db_prefix . $generated_username, 'database_user_prefix' => $client_db_prefix, - 'database_password' => substr(sha1(rand()), 0, 10) + 'database_password' => $app->auth->get_random_password($min_password_length, true); ); $db_user_id = $remote->insert_query('../sites/form/database_user.tform.php', $fields['client_id'], $db_user_params, 'sites:web_database_user:on_after_insert'); @@ -480,7 +483,7 @@ class page_action extends tform_actions { 'parent_domain_id' => $site_id, 'username' => $client_ftp_prefix . $generated_username, 'username_prefix' => $client_prefix, - 'password' => substr(sha1(rand()), 0, 10), + 'password' => $app->auth->get_random_password($min_password_length, true); 'quota_size' => $template['hd_quota'], 'dir' => $site_data['document_root'], 'uid' => $site_data['system_user'], @@ -517,7 +520,7 @@ class page_action extends tform_actions { if(isset($ftp_params)) { $ssh_params['password'] = $ftp_params['password']; } else { - $ssh_params['password'] = substr(sha1(rand()), 0, 10); + $ssh_params['password'] = $app->auth->get_random_password($min_password_length, true); } $remote->insert_query('../sites/form/shell_user.tform.php', $fields['client_id'], $ssh_params); -- GitLab From 60ce945797119cb6f9b676eee444682fbfd545cc Mon Sep 17 00:00:00 2001 From: Herman van Rink Date: Sat, 26 Jan 2019 21:58:12 +0100 Subject: [PATCH 2/2] Syntax fix --- new_service.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/new_service.php b/new_service.php index ea8fe2d..2e246ed 100644 --- a/new_service.php +++ b/new_service.php @@ -455,7 +455,7 @@ class page_action extends tform_actions { 'server_id' => $template['database_server_id'], 'database_user' => $client_db_prefix . $generated_username, 'database_user_prefix' => $client_db_prefix, - 'database_password' => $app->auth->get_random_password($min_password_length, true); + 'database_password' => $app->auth->get_random_password($min_password_length, true), ); $db_user_id = $remote->insert_query('../sites/form/database_user.tform.php', $fields['client_id'], $db_user_params, 'sites:web_database_user:on_after_insert'); @@ -483,7 +483,7 @@ class page_action extends tform_actions { 'parent_domain_id' => $site_id, 'username' => $client_ftp_prefix . $generated_username, 'username_prefix' => $client_prefix, - 'password' => $app->auth->get_random_password($min_password_length, true); + 'password' => $app->auth->get_random_password($min_password_length, true), 'quota_size' => $template['hd_quota'], 'dir' => $site_data['document_root'], 'uid' => $site_data['system_user'], -- GitLab