is hashing mechanism really secure?

Deadly 提交于 2019-12-03 21:58:00

No, just using hash, especially when just applying MD5 to the password, isn't secure because :

  • if you just convert a password (which is frequently almost a common word), it's easy to test it using a database of common passwords. So always use a salt and preferably a combination of other constant parts of the user record. Sometimes you may even find the origin of a hash by typing the hash in Google...
  • MD5 is prone to collisions, so even with a hash, prefer SHA 256 or better
  • MD5 is fast to compute, so fast to test in a brute force attack

Use the hashing mechanism but :

  • take a better hash function, for example SHA-256 or SHA-512
  • hash a constructed string, for example username+salt+password (you can use a constant salt as long as it's not used by other programs, it's enough for most uses)

The process when you register somebody (or somebody changes his password) is

1) to build the string s as s=username+salt+password (or a similar function)

2) to build the hash as SHA256(s)

3) to store in database the username, the salt (if not constant) and the hash

When authenticating a user, you build the hash in the same way (using the username and password given by the user and the salt you have in database) and you compare the username and the hash to what you have in database. You don't reverse the hash function, because that's not feasible.


Now regarding your code : your approach seems to be to generate all possible passwords until one has the same MD5 than the password you're trying to guess. This won't work for reasonable passwords because there isn't enough time to test all combinations of 15 characters.

Passwords are never stored in plaintext. At least they shouldn't be, unless you're building the world's most insecure system using the world's most naive programmers.

Instead, passwords are stored as the output of a hash function. Even if an attacker gained access to the hashed version of your password, it's not possible to reconstitute the password from the hash value alone.

But it is possible to attack the hashed value of your password using rainbow tables: enormous, pre-computed hash values for every possible combination of characters. An attacking PC could certainly calculate all these hashes on the fly, but taking advantage of a massive table of pre-computed hash values enables the attack to proceed several orders of magnitude faster-- assuming the attacking machine has enough RAM to store the entire table (or at least most of it) in memory. A table like this is called a rainbow table

It's a classic time-memory tradeoff, exactly the sort of cheating shortcut you'd expect a black hat attacker to take.

A database for follwing char set:ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=~[]{}|\:;"'<>,.?/ with a max password length of 14 would have a size of 64GB.

If you've salted your password hashes, an attacker can't use general rainbow table attack against you the hash results from "password" and "deliciously-salty-password" won't match. Unless your hacker somehow knows that all your hashes are "delicously-salty-" ones.

Even then, he or she would have to generate a custom rainbow table specifically for you.

Please read Thomas Ptacek's excellent and informative article on this topic. It goes into much more detal about the nuts and bolts of password hashing.

And finally the answer to your Question:

NO it is not secure, but you can do your best to make it as secure as possible.

No. Hashing passwords is not secure, but it's more secure than not doing this. As you can see such hashed passwords might be easily decrypted if you have enough time and hardware resources. This is why we often use salt to make our passwords more secure. The salt is something that is somehow merged with the real password and you store the hashcode of such string. The attacker might be able to break the encryption but he receives the password mixed with salt. This is a quite good protection to people who use so called 'rainbow tables' to decrypt the passwords. Unfortunatelly it's still breakable. Here you can find more info about that: http://arstechnica.com/security/2012/08/passwords-under-assault/

No, they are not 100% secure, specially if the attacker has a hash database. A better approach is to use salted passwords, as this make hash databases quite useless.

Another way to make the password a bit more secure is to hash it several times, which also reduces the effectiveness of a hash database.

As other posts mentioned, pick a more secure and expensive algorithm like sha-512.

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