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);
}
}