Skip to content

Commit aad102f

Browse files
author
Till Brehm
committed
Fixed #4033 Special characters in email mailbox password
1 parent 74fbcbc commit aad102f

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

interface/lib/classes/auth.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ public function get_random_password($minLength = 8, $special = false) {
213213
return str_shuffle($password);
214214
}
215215

216-
public function crypt_password($cleartext_password) {
216+
public function crypt_password($cleartext_password, $charset = 'UTF-8') {
217+
if($charset != 'UTF-8') {
218+
$cleartext_password = mb_convert_encoding($cleartext_password, $charset, 'UTF-8');
219+
}
217220
$salt="$1$";
218221
$base64_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
219222
for ($n=0;$n<8;$n++) {

interface/lib/classes/tform_base.inc.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,9 @@ function filterField($field_name, $field_value, $filters, $filter_event) {
901901
case 'IDNTOUTF8':
902902
$returnval = $app->functions->idn_decode($returnval);
903903
break;
904+
case 'TOLATIN1':
905+
$returnval = mb_convert_encoding($returnval, 'ISO-8859-1', 'UTF-8');
906+
break;
904907
case 'TRIM':
905908
$returnval = trim($returnval);
906909
break;
@@ -1263,6 +1266,10 @@ protected function _getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $
12631266
} elseif(isset($field['encryption']) && $field['encryption'] == 'CRYPT') {
12641267
$record[$key] = $app->auth->crypt_password(stripslashes($record[$key]));
12651268
$sql_insert_val .= "'".$app->db->quote($record[$key])."', ";
1269+
} elseif(isset($field['encryption']) && $field['encryption'] == 'CRYPTMAIL') {
1270+
// The password for the mail system needs to be converted to latin1 before it is hashed.
1271+
$record[$key] = $app->auth->crypt_password(stripslashes($record[$key]),'ISO-8859-1');
1272+
$sql_insert_val .= "'".$app->db->quote($record[$key])."', ";
12661273
} elseif (isset($field['encryption']) && $field['encryption'] == 'MYSQL') {
12671274
$tmp = $app->db->queryOneRecord("SELECT PASSWORD(?) as `crypted`", stripslashes($record[$key]));
12681275
$record[$key] = $tmp['crypted'];
@@ -1291,6 +1298,10 @@ protected function _getSQL($record, $tab, $action = 'INSERT', $primary_id = 0, $
12911298
} elseif(isset($field['encryption']) && $field['encryption'] == 'CRYPT') {
12921299
$record[$key] = $app->auth->crypt_password(stripslashes($record[$key]));
12931300
$sql_update .= "`$key` = '".$app->db->quote($record[$key])."', ";
1301+
} elseif(isset($field['encryption']) && $field['encryption'] == 'CRYPTMAIL') {
1302+
// The password for the mail system needs to be converted to latin1 before it is hashed.
1303+
$record[$key] = $app->auth->crypt_password(stripslashes($record[$key]),'ISO-8859-1');
1304+
$sql_update .= "`$key` = '".$app->db->quote($record[$key])."', ";
12941305
} elseif (isset($field['encryption']) && $field['encryption'] == 'MYSQL') {
12951306
$tmp = $app->db->queryOneRecord("SELECT PASSWORD(?) as `crypted`", stripslashes($record[$key]));
12961307
$record[$key] = $tmp['crypted'];

interface/web/mail/form/mail_user.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
'errmsg' => 'weak_password_txt'
129129
)
130130
),
131-
'encryption'=> 'CRYPT',
131+
'encryption'=> 'CRYPTMAIL',
132132
'default' => '',
133133
'value' => '',
134134
'width' => '30',

interface/web/mail/mail_user_edit.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ function onSubmit() {
143143
if($domain["domain"] != $app->functions->idn_encode($_POST["email_domain"])) $app->tform->errorMessage .= $app->tform->lng("no_domain_perm");
144144
}
145145

146-
147146
//* if its an insert, check that the password is not empty
148147
if($this->id == 0 && $_POST["password"] == '') {
149148
$app->tform->errorMessage .= $app->tform->lng("error_no_pwd")."<br>";

0 commit comments

Comments
 (0)