doufu5521 2012-07-27 13:38
浏览 61
已采纳

Crypt函数为相同的密码生成相同的哈希值

I'm trying to create an hashing function that, given a random salt, generates a password hash from it.

The problem is, that, if I enter the same password for two different users, the hash generated is the same for both.

Waht might be the problem?

public function generateSalt()
{       


     return $salt = substr(sha1(uniqid(rand(), true)), 0, 32);
}

public function pwdEncrypt($password, $salt)
{       

    $hash = crypt($password, '$2a$' . $salt . '$');     
    return $hash;
}

public function registerUser($nome, $email, $password, $permitions, $active)
{



    $this->nome = $nome;
    $this->email = $email;


    $salt = $this->generateSalt();


    $this->password = $this->pwdEncrypt($password, $salt);

   //INSERT METHODS BELOW
}
  • 写回答

2条回答 默认 最新

  • douba2705 2012-07-27 13:45
    关注

    That's not how you use crypt with blowfish ($2a$)

    You need to specify the strength, and the salt at the end.

    Try this crypt($password, '$2a$08$'.$salt);

    Obviously increase the strength to improve security, at the expense of processing time.

    I should also add, if you are using a PHP version greater than 5.3.7, you should use $2y$ for your blowfish algorithm, as an attack for $2a$ was discovered in 2011.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探