From 6915818678cc15b514f66288b5fc36c6013d176e Mon Sep 17 00:00:00 2001 From: Yuan Chiu Date: Sun, 23 Nov 2014 18:17:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=89=AF=E5=AF=86=E7=A2=BC=E9=A9=97?= =?UTF-8?q?=E8=AD=89:=20=E6=94=B9=E6=88=90=E6=9C=83=E5=98=97=E8=A9=A6?= =?UTF-8?q?=E6=89=80=E6=9C=89=E7=9A=84=E5=8A=A0=E5=AF=86=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/lib/User/User.php | 2 +- htdocs/lib/User/UserAdmin.php | 2 -- htdocs/lib/Util/Password.php | 24 +++++++++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/htdocs/lib/User/User.php b/htdocs/lib/User/User.php index 330e697..b873f5e 100644 --- a/htdocs/lib/User/User.php +++ b/htdocs/lib/User/User.php @@ -139,7 +139,7 @@ class User { public function isPasswordCorrect($inputPasswd){ $passUtil = new Util\Password(); $this_passwd = $this->queryResultArray['password']; - return $passUtil->checkSame($this_passwd, $inputPasswd); + return $passUtil->checkSameTryAll($this_passwd, $inputPasswd); } /** diff --git a/htdocs/lib/User/UserAdmin.php b/htdocs/lib/User/UserAdmin.php index af7a733..b63cc28 100644 --- a/htdocs/lib/User/UserAdmin.php +++ b/htdocs/lib/User/UserAdmin.php @@ -53,8 +53,6 @@ class UserAdmin { * @param array $userInfoArray 使用者資訊陣列,格式為: * array( 'user_id' => 'root', * 'password' => 'pass123', - * 'password_encrypt' => null, // (optional) 預設為null - * 'password_encrypted' => null, // (optional) 預設為false * 'group_id' => 'user', * 'class_id' => '5-2', // (optional) * 'enable' => true, // (optional) 預設為true diff --git a/htdocs/lib/Util/Password.php b/htdocs/lib/Util/Password.php index 37ec503..afa1b82 100644 --- a/htdocs/lib/Util/Password.php +++ b/htdocs/lib/Util/Password.php @@ -104,7 +104,7 @@ class Password { } /** - * 加密這段字 + * 確認是否吻合 * * @param string $encrypted 已加密字串 * @param string $text 原本字串 @@ -124,6 +124,28 @@ class Password { } } + /** + * 確認所有的加密法是否吻合 + * + * @param string $encrypted 已加密字串 + * @param string $text 原本字串 + * @return bool true代表與加密後字串一樣 + * @since 2.0.0 + */ + public function checkSameTryAll($encrypted, $text) { + // 判斷是否吻合 + switch($encrypted) { + case $this->encrypt($text): + case $text: + case $this->sha1Encrypt($text): + case $this->md5Encrypt($text): + case $this->cryptEncrypt($text): + return true; + default: + return false; + } + } + // ------------------------------------------------------------------------ /**