From a9923f5dc131f5a18175b1df3cf3f80a93ffb464 Mon Sep 17 00:00:00 2001 From: Daniel Morris Date: Wed, 3 Oct 2012 19:37:09 +0100 Subject: Support for hashing algorithms other than SHA1 and MD5 Signed-off-by: Daniel Morris --- system/libraries/Encrypt.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/libraries/Encrypt.php') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 8ffd93aea..3b04f7b06 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -484,7 +484,7 @@ class CI_Encrypt { */ public function set_hash($type = 'sha1') { - $this->_hash_type = ($type !== 'sha1' && $type !== 'md5') ? 'sha1' : $type; + $this->_hash_type = (in_array($type, hash_algos())) ? $type : 'sha1'; } // -------------------------------------------------------------------- @@ -497,7 +497,7 @@ class CI_Encrypt { */ public function hash($str) { - return ($this->_hash_type === 'sha1') ? sha1($str) : md5($str); + return hash($this->_hash_type, $str); } } -- cgit v1.2.3-24-g4f1b From ada7775a47f32034ba589768612894c3cb6186ca Mon Sep 17 00:00:00 2001 From: Daniel Morris Date: Thu, 4 Oct 2012 10:24:16 +0100 Subject: Removed redundant parenthesis around `in_array()` --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Encrypt.php') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 3b04f7b06..679609251 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -484,7 +484,7 @@ class CI_Encrypt { */ public function set_hash($type = 'sha1') { - $this->_hash_type = (in_array($type, hash_algos())) ? $type : 'sha1'; + $this->_hash_type = in_array($type, hash_algos()) ? $type : 'sha1'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c6f9a5da098ed9e27d88b7c271c4e1ba76fa79d6 Mon Sep 17 00:00:00 2001 From: lysenkobv Date: Wed, 10 Oct 2012 20:11:34 +0300 Subject: libraries/Encrypt.php decode improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if base64 string is NO valid the result of decoded string is something like this "23Y�����������S�� �����i��!q" (base64_encode(base64_decode($string)) !== $string) check is this base64 string valid --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Encrypt.php') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 679609251..dbe16b096 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -165,7 +165,7 @@ class CI_Encrypt { */ public function decode($string, $key = '') { - if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) || base64_encode(base64_decode($string)) !== $string) { return FALSE; } -- cgit v1.2.3-24-g4f1b From c16b4f4164a4a26c48b823caf086a9777dc75beb Mon Sep 17 00:00:00 2001 From: Bogdan Lysenko Date: Thu, 11 Oct 2012 11:41:01 +0300 Subject: Update system/libraries/Encrypt.php --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/libraries/Encrypt.php') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index dbe16b096..73ab8ca7d 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -165,7 +165,7 @@ class CI_Encrypt { */ public function decode($string, $key = '') { - if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) || base64_encode(base64_decode($string)) !== $string) + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) OR base64_encode(base64_decode($string)) !== $string) { return FALSE; } -- cgit v1.2.3-24-g4f1b