Skip to content

Commit d915890

Browse files
committed
Fix hestiacp#1062 passwords not accepting special chars
1 parent 798cf36 commit d915890

File tree

7 files changed

+18
-8
lines changed

7 files changed

+18
-8
lines changed

web/add/db/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
// Check password length
4444
if (empty($_SESSION['error_msg'])) {
45-
if (!preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/', $_POST['v_password'])) { $_SESSION['error_msg'] = __('Password does not match the minimum requirements'); }
45+
if (!validate_password($_POST['v_password'])) { $_SESSION['error_msg'] = __('Password does not match the minimum requirements');}
4646
}
4747

4848
// Protect input

web/add/mail/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123

124124
// Check password length
125125
if (empty($_SESSION['error_msg']) && !empty($_POST['v_fwd_only']) ) {
126-
if (!preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/', $_POST['v_password'])) { $_SESSION['error_msg'] = __('Password does not match the minimum requirements'); }
126+
if (!validate_password($_POST['v_password'])) { $_SESSION['error_msg'] = __('Password does not match the minimum requirements');}
127127
}
128128

129129
// Protect input

web/add/user/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
// Check password length
4747
if (empty($_SESSION['error_msg'])) {
48-
if (!preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/', $_POST['v_password'])) { $_SESSION['error_msg'] = __('Password does not match the minimum requirements'); }
48+
if (!validate_password($_POST['v_password'])) { $_SESSION['error_msg'] = __('Password does not match the minimum requirements'); }
4949
}
5050

5151
// Protect input

web/edit/db/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363

6464
// Change database password
6565
if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
66-
if (!preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/', $_POST['v_password'])) {
67-
$_SESSION['error_msg'] = __('Password does not match the minimum requirements');
66+
if (!validate_password($_POST['v_password'])) {
67+
$_SESSION['error_msg'] = __('Password does not match the minimum requirements');
6868
}else{
6969
$v_password = tempnam("/tmp","vst");
7070
$fp = fopen($v_password, "w");

web/edit/mail/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@
398398

399399
// Change password
400400
if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
401-
if (!preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/', $_POST['v_password'])) {
402-
$_SESSION['error_msg'] = __('Password does not match the minimum requirements');
401+
if (!validate_password($_POST['v_password'])) {
402+
$_SESSION['error_msg'] = __('Password does not match the minimum requirements');
403403
}else{
404404
$v_password = tempnam("/tmp","vst");
405405
$fp = fopen($v_password, "w");

web/edit/user/index.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@
100100
if ((!empty($_POST['v_password'])) && (empty($_SESSION['error_msg']))) {
101101
// Check password length
102102
$pw_len = strlen($_POST['v_password']);
103-
if (!preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/', $_POST['v_password'])) { $_SESSION['error_msg'] = __('Password does not match the minimum requirements'); }
103+
if (!validate_password($_POST['v_password'])) {
104+
$_SESSION['error_msg'] = __('Password does not match the minimum requirements');
105+
}
104106
if (empty($_SESSION['error_msg'])) {
105107
$v_password = tempnam("/tmp","vst");
106108
$fp = fopen($v_password, "w");

web/inc/main.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,11 @@ function backendtpl_with_webdomains() {
385385
}
386386
return $backend_list;
387387
}
388+
/**
389+
* Check if password is valid
390+
*
391+
* @return int; 1 / 0
392+
*/
393+
function validate_password($password){
394+
return preg_match('/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(.){8,}$/', $password);
395+
}

0 commit comments

Comments
 (0)