From 5c9b0b0d75e2635df48d3325375e714b37075d8a Mon Sep 17 00:00:00 2001 From: Miguel Date: Fri, 2 Aug 2019 10:01:48 +0200 Subject: [PATCH] Add support for multibyte string Issue #5 : Cannot authentificate with a specific special character in password. Add support for multibyte string (https://www.php.net/manual/en/book.mbstring.php) in str2unicode function (Pear_CHAP.php). Function interprets all characters with 1 byte (basic UTF-8) while special characters are encoded with more than 1 byte (see column UTF-8(hex.) in https://www.utf8-chartable.de/unicode-utf8-table.pl?names=-&unicodeinhtml=hex). --- lib/Pear_CHAP.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Pear_CHAP.php b/lib/Pear_CHAP.php index aa6878e..0531cf5 100644 --- a/lib/Pear_CHAP.php +++ b/lib/Pear_CHAP.php @@ -240,8 +240,8 @@ public function str2unicode($str) { $uni = ''; $str = (string) $str; - for ($i = 0; $i < strlen($str); $i++) { - $a = ord($str{$i}) << 8; + for ($i = 0; $i < mb_strlen($str); $i++) { + $a = mb_ord(mb_substr($str,$i,1)) << 8; $uni .= sprintf("%X", $a); } return pack('H*', $uni);