改良密碼驗證: 改成會嘗試所有的加密法

This commit is contained in:
Yuan Chiu 2014-11-23 18:17:31 +08:00
parent 01ddc82f59
commit 6915818678
3 changed files with 24 additions and 4 deletions

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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;
}
}
// ------------------------------------------------------------------------
/**