2015-10-14 33 views

回答

0

呃......我認爲這比我想象的要簡單。

蛋糕認證要求從驗證密碼方法,然後從安全類調​​用哈希

//Auth class 
function password($password) { 
    return Security::hash($password, null, true); 
} 

安全,默認情況下,它使用SHA1方法與鹽和密碼串接;鹽是蛋糕安裝過程中生成的一個隨機字符串,他的值寫在core.php文件中。

//Security class 
function hash($string, $type = null, $salt = false) { 
    $_this = Security::getInstance(); 

    if ($salt) { 
     if (is_string($salt)) { 
      $string = $salt . $string; 
     } else { 
      $string = Configure::read('Security.salt') . $string; 
     } 
    } 

    if (empty($type)) { 
     $type = $_this->hashType; 
    } 
    $type = strtolower($type); 

    if ($type == 'sha1' || $type == null) { 
     if (function_exists('sha1')) { 
      $return = sha1($string); 
      return $return; 
     } 
     $type = 'sha256'; 
    } 

    //... 
} 

然後,我需要的是將此實現帶到下一個系統並標記來自新用戶的以前的用戶。首次登錄時,用戶將看到一個表單,使用新系統中的新哈希方法輸入新密碼。