Is this a good way to encrypt passwords with MD5?

我怕爱的太早我们不能终老 提交于 2019-12-02 11:48:36
SLaks

Password hashes should be slow, not fast.
The faster the hash, the faster an attacker can run through a password dictionary.

Therefore, you should never use general-purpose hashes like SHA for passwords.

Instead, use proven slow techniques like scrypt or PBKDF2.

slfan

I would store only the salt value and the hash (not the saltedencryptedPassword) in separate columns in the database and regenerate the hash with the typed in password. You find a similar answer here Hash and salt passwords in C#.1`

I sometimes just us a GUID as a salt value and add it to the password before hashing.

MD5 is not safe any longer (hacked in 2004 by the Chinese), you can use SHA256 or SHA512 instead of. EDIT: However these algorithmes are pretty fast in calculation and therefore easier to hack. @SLaks suggests to use scrypt or PBKDF2, because they are much harder to calculate. There is a built-in implementation of PBKDF2 in .NET under Rfc2898DeriveBytes.

Another point: I would not create a new Random() object every time. If you call this within short period time the same sequence of random numbers will be generated every time, because the seed value is time based.

No, it's no good. MD5 is no good anymore. It collides with itself and not to be trusted. You should use SHA256.

public string getSHA256(string input)
{
    try
    {
        return BitConverter.ToString(SHA256Managed.Create().ComputeHash(Encoding.Default.GetBytes(input))).Replace(“-”, “”).ToLower();
    }
    catch (Exception e)
    {
        return string.Empty;
    }
}

I always use SHA2-512 for the hashing of my passwords. In my opinion passwords should never be encrypted, but always hashed (no way to trace back to the original password).

But please no longer use MD5, which is easily translated back in a password nowadays.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!