简体   繁体   English

php MD5中的密码散列

[英]Password hashing in php MD5

Can anyone tell me whats wrong with this?谁能告诉我这有什么问题吗?

function hashmyshit($pass){

        for ( $i = 0; $i < 1000; $i++ ){
            MD5($pass);
        }
        return $pass;
}

and how to iterate a password hashing process many times.以及如何多次迭代密码散列过程。

You should use :你应该使用:

$pass = md5($pass);

instead of代替

MD5($pass);

But in fact, what do you want to achieve?但事实上,你想达到什么目的? Why do you want do md5 many times on strings that md5 was already done?为什么要在 md5 已经完成的字符串上多次执行 md5? What's the purpose?目的是什么? If you simply want to safely encrypt password you should choose user better encryption method using password_hash() function.如果您只是想安全地加密密码,您应该使用password_hash()函数选择用户更好的加密方法。

Using the same encrypt function many times may even cause that it's easier attacker to get into your system, so you shouldn't do such things.多次使用相同的加密功能甚至可能导致攻击者更容易进入您的系统,因此您不应该这样做。

Accordingly if you want to hash the password a 1000 times then you can do like this:因此,如果您想对密码进行 1000 次散列,那么您可以这样做:

function hashmyshit($pass){
    $password = $pass;
    for ( $i = 0; $i < 1000; $i++ ){
        $password = md5($password);
    }
    return $password;
}

Previously you were trying to hash the same $pass a 1000 times.以前,您试图将相同的$pass散列 1000 次。 But as @Marcin Nabiałek said this is not the appropriate method to secure the passwords, you should use in-built encryption.但正如@Marcin Nabiałek 所说,这不是保护密码的适当方法,您应该使用内置加密。

I would strongly refrain from using MD5, due to the many cryptographic weaknesses found in the algorithm and for other obvious reasons which Philipp is kind enough to elaborate on in the following post ;我强烈避免使用 MD5,因为在算法中发现了许多加密弱点,并且出于其他明显的原因,Philipp 在下面的帖子中详细说明了这些原因;

https://security.stackexchange.com/questions/52461/how-weak-is-md5-as-a-password-hashing-function https://security.stackexchange.com/questions/52461/how-weak-is-md5-as-a-password-hashing-function

Try BCrypt Instead试试BCrypt

Andrew Moore explains in this post how to use bcrypt for hashing passwords in PHP? Andrew Moore 在这篇文章中解释了如何在 PHP 中使用 bcrypt 对密码进行散列?

How do you use bcrypt for hashing passwords in PHP? 你如何使用 bcrypt 在 PHP 中散列密码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM