【发布时间】:2011-09-13 00:10:21
【问题描述】:
我正在使用这个类来创建密码哈希。该系统由一个基于 php、iphone 设备和 android 设备构建的网页组成。我需要这些智能手机能够登录并访问存储在我的数据库服务器端的信息。最好的解决方案是什么,是否将此方法移植到目标 c 并将哈希发送到服务器?还是使用 SSL 发送密码并比较哈希服务器端更好?
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);
}
}
【问题讨论】:
标签: php objective-c authentication ssl hash