我正在使用此类来创建密码哈希。该系统由一个基于 php、iphone 设备和 android 设备的网页组成。我需要这些智能手机能够登录并访问存储在我的数据库服务器端的信息。最好的解决方案是什么,是将此方法移植到 objective-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);
}
}
最佳答案
将哈希“移植”到移动应用程序并不是一个好主意。服务器的散列是唯一的,您不希望在不同的设备平台上使用不同的“散列”方法。
在 SSL 中发送密码并让您的服务器端身份验证模型进行哈希处理。
关于php - PHP 和智能手机设备之间的密码验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6315336/