2011-06-11 57 views
2

我正在使用這個類來創建密碼哈希。該系統由建立在php,iphone設備和android設備上的網頁組成。我需要這些智能手機才能登錄並訪問存儲在我的數據庫服務器端的信息。什麼是最好的解決方案,是將此方法移植到目標c並將散列發送到服務器?或者使用SSL發送密碼並比較哈希服務器端更好?PHP和智能手機設備之間的密碼驗證

class PassHash { 

    // blowfish 
    private static $algo = '$2a'; 

    // cost parameter 
    private static $cost = '$10'; 

    // mainly for internal use 
    public static function unique_salt() { 
    return substr(sha1(mt_rand()),0,22); 
    } 

    // this will be used to generate a hash 
    public static function hash($password) { 

    return crypt($password, 
       self::$algo . 
       self::$cost . 
       '$' . self::unique_salt()); 

    } 

    // this will be used to compare a password against a hash 
    public static function check_password($hash, $password) { 

    $full_salt = substr($hash, 0, 29); 

    $new_hash = crypt($password, $full_salt); 

    return ($hash == $new_hash); 

    } 
} 

回答

0

「移植哈希」到移動應用程序不是一個好主意。服務器的散列​​是唯一的,您不希望跨不同設備平臺使用不同的「散列」方法。

在SSL中發送密碼並讓您的服務器端認證模型執行散列。