English 中文(简体)
php密码问题
原标题:php crypt problem

我正在尝试以加密格式存储密码,但它似乎无法正常工作。这是我正在使用的php代码。

function encryptMe($input, $salt){
    $output = crypt($input,$salt);
return $output;
}

function getSalt(){
   //set number of repititions
   $reps="5000";

   $salt = substr(str_replace( + ,  . , base64_encode(
            pack( N4 , mt_rand(), mt_rand(), mt_rand(), mt_rand())
            )), 0, 16);
   $salt = "$6$"."rounds=".$reps."$".$salt;     
   return $salt;    
}

我的代码中也有以下语句。

$input[ password ] = $_POST[ password ];
$salt = getSalt();
$input[ password ] = encryptMe($input[ password ],$salt);

我已经用不同的salt但相同的密码运行了多次,并且一直得到相同的散列。换盐似乎没有任何效果,我也不知道出了什么问题。有人能看看这个代码并帮助我吗?

还有什么方法可以确认这是在使用SHA512吗?

问题回答

这是因为crypt()只返回几个第一个字符,所以输入即使不同,也可能返回相同的字符串,因为只有最后一个字符发生了变化。

另一种方法是使用hash()用于SHA-256。有人已经在你的帖子中给你分享了一个非常有趣的链接。

编辑

这就是vBulletin加密密码。不知道他们是否仍在使用这种方法。

$password_hash = md5(md5($password_text) . $user_salt);
// $user_salt is a random three character string stored 
// in the user table as  salt .




相关问题
Extend Contacts application on Android to provide encryption

I want to encrypt individual contacts stored by the Contacts application on Android based on user s preference. So, I am thinking I ll have to hook/extend the Contacts application before the it stores ...

Make md5 strong

Im making a website that will intergrate with game that only support md5 hashing metod (atm). Which ofc is not especially safe anymore. But how could i make it stronger? Should I just generate long ...

How to Pack/Encrypt/Unpack/Decrypt a bunch of files in Java?

I m essentially trying to do the following on a Java/JSP-driven web site: User supplies a password Password is used to build a strongly-encrypted archive file (zip, or anything else) containing a ...

Thread & Queue vs Serial performance

I though it ll be interesting to look at threads and queues, so I ve written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I m still very new ...

Convert PHP encryption code to C#

I m trying to convert this piece of code from PHP to C#. It s part of a Captive Portal. Could somebody explain what it does? $hexchal = pack ("H32", $challenge); if ($uamsecret) { $newchal = ...

Encryption: how to have 1 iv despite multiple fields

I ve been stuck trying to arrive at a best solution for this for a while. I know that an initialization vector has to be unique for each item being encrypted. So if I m encrypting an address and I ...

热门标签