Php 不同系统中的储罐认证(;Mac和Linux);创建不同的密码哈希代码
我使用mac作为web服务器,使用codeigniter作为框架。为了认证,我申请了坦克认证。出现了一个问题: 以前:我使用mac作为web服务器,登录很好 现在:我使用linux作为web服务器。我导入了相同的数据库,网站运行良好。但是,我无法登录 所以我在mac和linux中测试了使用相同密码注册,发现它创建了不同的密码哈希代码 Linux:Php 不同系统中的储罐认证(;Mac和Linux);创建不同的密码哈希代码,php,codeigniter,md5,tankauth,Php,Codeigniter,Md5,Tankauth,我使用mac作为web服务器,使用codeigniter作为框架。为了认证,我申请了坦克认证。出现了一个问题: 以前:我使用mac作为web服务器,登录很好 现在:我使用linux作为web服务器。我导入了相同的数据库,网站运行良好。但是,我无法登录 所以我在mac和linux中测试了使用相同密码注册,发现它创建了不同的密码哈希代码 Linux: $P$Bh3B8uGDw0yGO1e/ytCUw2jXcswkso1 Mac: 我的问题是:这个问题是关于系统的吗?还是php版本 还是关于php的
$P$Bh3B8uGDw0yGO1e/ytCUw2jXcswkso1
Mac:
我的问题是:这个问题是关于系统的吗?还是php版本
还是关于php的md5()函数
我在tank auth中提供了一些密码哈希代码:
function PasswordHash($iteration_count_log2, $portable_hashes)
{
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
$iteration_count_log2 = 8;
$this->iteration_count_log2 = $iteration_count_log2;
$this->portable_hashes = $portable_hashes;
$this->random_state = microtime();
if (function_exists('getmypid'))
$this->random_state .= getmypid();
}
function get_random_bytes($count)
{
$output = '';
if (is_readable('/dev/urandom') &&
($fh = @fopen('/dev/urandom', 'rb'))) {
$output = fread($fh, $count);
fclose($fh);
}
if (strlen($output) < $count) {
$output = '';
for ($i = 0; $i < $count; $i += 16) {
$this->random_state =
md5(microtime() . $this->random_state);
$output .=
pack('H*', md5($this->random_state));
}
$output = substr($output, 0, $count);
}
return $output;
}
function encode64($input, $count)
{
$output = '';
$i = 0;
do {
$value = ord($input[$i++]);
$output .= $this->itoa64[$value & 0x3f];
if ($i < $count)
$value |= ord($input[$i]) << 8;
$output .= $this->itoa64[($value >> 6) & 0x3f];
if ($i++ >= $count)
break;
if ($i < $count)
$value |= ord($input[$i]) << 16;
$output .= $this->itoa64[($value >> 12) & 0x3f];
if ($i++ >= $count)
break;
$output .= $this->itoa64[($value >> 18) & 0x3f];
} while ($i < $count);
return $output;
}
function HashPassword($password)
{
$random = '';
if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
$random = $this->get_random_bytes(16);
$hash =
crypt($password, $this->gensalt_blowfish($random));
if (strlen($hash) == 60)
return $hash;
}
if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
if (strlen($random) < 3)
$random = $this->get_random_bytes(3);
$hash =
crypt($password, $this->gensalt_extended($random));
if (strlen($hash) == 20)
return $hash;
}
if (strlen($random) < 6)
$random = $this->get_random_bytes(6);
$hash =
$this->crypt_private($password,
$this->gensalt_private($random));
if (strlen($hash) == 34)
return $hash;
# Returning '*' on error is safe here, but would _not_ be safe
# in a crypt(3)-like function used _both_ for generating new
# hashes and for validating passwords against existing hashes.
return '*';
}
函数密码哈希($iteration\u count\u log2,$portable\u hash)
{
$this->itoa64='./0123456789abcdefghijklmnopqrstuvwxyzabefghijklmnopqrstuvxyz';
如果($iteration_count_log2<4||$iteration_count_log2>31)
$iteration\u count\u log2=8;
$this->iteration\u count\u log2=$iteration\u count\u log2;
$this->portable\u hashes=$portable\u hashes;
$this->random_state=microtime();
如果(函数_存在('getmypid'))
$this->random_state.=getmypid();
}
函数获取随机字节($count)
{
$output='';
如果(是可读的('/dev/uradom'))&&
($fh=@fopen('/dev/uradom','rb')){
$output=fread($fh,$count);
fclose($fh);
}
如果(strlen($output)<$count){
$output='';
对于($i=0;$i<$count;$i+=16){
$this->random_state=
md5(microtime().$this->random_state);
$output=
包装('H*',md5($this->random_state));
}
$output=substr($output,0,$count);
}
返回$output;
}
函数encode64($input,$count)
{
$output='';
$i=0;
做{
$value=ord($input[$i++]);
$output.=$this->itoa64[$value&0x3f];
如果($i<$count)
$value |=ord($input[$i])itoa64[($value>>6)和0x3f];
如果($i++>=$count)
打破
如果($i<$count)
$value |=ord($input[$i])itoa64[($value>>12)和0x3f];
如果($i++>=$count)
打破
$output.=$this->itoa64[($value>>18)和0x3f];
}而($i<$count);
返回$output;
}
函数HashPassword($password)
{
$random='';
if(CRYPT_河豚==1&&!$this->portable_散列){
$random=$this->get_random_字节(16);
$hash=
crypt($password,$this->gensalt_河豚($random));
if(strlen($hash)==60)
返回$hash;
}
if(CRYPT_EXT_DES==1&&!$this->portable_hashes){
if(strlen($random)<3)
$random=$this->get_random_字节(3);
$hash=
crypt($password,$this->gensalt_extended($random));
if(strlen($hash)==20)
返回$hash;
}
if(strlen($random)<6)
$random=$this->get_random_字节(6);
$hash=
$this->crypt_private($password,
$this->gensalt_private($random));
if(strlen($hash)==34)
返回$hash;
#在出错时返回“*”在这里是安全的,但是不安全吗
#在类crypt(3)函数中,用于生成新的
#哈希和用于根据现有哈希验证密码。
返回“*”;
}
有什么想法吗?我在谷歌上搜索了这个问题,但得到的信息很少,你能帮我吗?谢谢
哦,也许是关于地下室河豚的。Linux没有CRYPT_河豚。我自己找到了解决方案 问题是关于php版本的 PHP5.2不受CRYPT_BLOWFISH支持,但PHP5.3可以 谢谢大家。Cf。
function PasswordHash($iteration_count_log2, $portable_hashes)
{
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
if ($iteration_count_log2 < 4 || $iteration_count_log2 > 31)
$iteration_count_log2 = 8;
$this->iteration_count_log2 = $iteration_count_log2;
$this->portable_hashes = $portable_hashes;
$this->random_state = microtime();
if (function_exists('getmypid'))
$this->random_state .= getmypid();
}
function get_random_bytes($count)
{
$output = '';
if (is_readable('/dev/urandom') &&
($fh = @fopen('/dev/urandom', 'rb'))) {
$output = fread($fh, $count);
fclose($fh);
}
if (strlen($output) < $count) {
$output = '';
for ($i = 0; $i < $count; $i += 16) {
$this->random_state =
md5(microtime() . $this->random_state);
$output .=
pack('H*', md5($this->random_state));
}
$output = substr($output, 0, $count);
}
return $output;
}
function encode64($input, $count)
{
$output = '';
$i = 0;
do {
$value = ord($input[$i++]);
$output .= $this->itoa64[$value & 0x3f];
if ($i < $count)
$value |= ord($input[$i]) << 8;
$output .= $this->itoa64[($value >> 6) & 0x3f];
if ($i++ >= $count)
break;
if ($i < $count)
$value |= ord($input[$i]) << 16;
$output .= $this->itoa64[($value >> 12) & 0x3f];
if ($i++ >= $count)
break;
$output .= $this->itoa64[($value >> 18) & 0x3f];
} while ($i < $count);
return $output;
}
function HashPassword($password)
{
$random = '';
if (CRYPT_BLOWFISH == 1 && !$this->portable_hashes) {
$random = $this->get_random_bytes(16);
$hash =
crypt($password, $this->gensalt_blowfish($random));
if (strlen($hash) == 60)
return $hash;
}
if (CRYPT_EXT_DES == 1 && !$this->portable_hashes) {
if (strlen($random) < 3)
$random = $this->get_random_bytes(3);
$hash =
crypt($password, $this->gensalt_extended($random));
if (strlen($hash) == 20)
return $hash;
}
if (strlen($random) < 6)
$random = $this->get_random_bytes(6);
$hash =
$this->crypt_private($password,
$this->gensalt_private($random));
if (strlen($hash) == 34)
return $hash;
# Returning '*' on error is safe here, but would _not_ be safe
# in a crypt(3)-like function used _both_ for generating new
# hashes and for validating passwords against existing hashes.
return '*';
}