How to securely store passwords



Whether developing App or Web site, as long as the user logs in part, it will involve the issue of how to store a user's password. If the technology used to store the password is not secure enough, once hackers broke into a database to store the password, he can get the user's password and thus may cause significant losses to the user. This situation any company do not want to happen to them, so choose to securely store the password policy is very necessary.

Do not have their own store user passwords

The easiest way to store the password is not stored their own, but a third party store you trust. This is the OpenID technology, its philosophy is to complete the operation by the third-party user authentication. At present, foreign sites such as Google, Yahoo and so on, and so has the country such as Tencent to provide OpenID service. If we choose to develop a website and Google's OpenID service, the user can use Gmail login account and password, the next thing will be to complete the user authentication Google.

Using OpenID technology both for the developer or user of the site, it has obvious advantages. Since the user's login authentication by the third-party OpenID complete service provider, we own no need to store user names and passwords, there is no need to consider security implications of storing passwords, thus reducing the cost of development. At the same time, users do not have to register a new username and password on our website. This not only eliminates the need for users to fill out information when registering a user name and password trouble, minus the user needs to remember the burden of a new pair of user name and password.

Do not store passwords in plain text

There are many companies for various reasons do not want to put their client's login information is stored in other companies, and it had its own store the user's password. Since the decision to own store, we must consider the safety of storage. Minimum requirements for password storage is not (not encrypted) stored passwords in clear text. If you store passwords in plain text, once leaked database, all the user's password unreservedly exposed to hackers before, which could bring huge losses to customers and the company.

Although not obvious passwords stored in clear text with the truth, but in fact there are still many companies use this extremely unsafe manner. This website passwords leaked from a variety of events that can be seen from time to time burst. For those companies are still stored in clear text passwords, we can only advise them as soon as possible using a hashing algorithm to encrypt the password again after storage, do not wait until after password leaks caused heavy losses Fanran Dawu.

With a hashing algorithm to encrypt passwords

Commonly used for password encryption algorithm is one-way hash algorithm several. The so-called one-way algorithm means that we can only generate a hash value from the corresponding plaintext, but not to the plain text in turn worth a hash. It often used for encryption algorithm MD5 and SHA series (such as SHA1 , SHA256 , SHA384 , SHA512 , etc.). It is noteworthy that, MD5 algorithm has been cracked Chinese mathematician Wang Xiaoyun, so this method is no longer recommended in the product.

Although a hash algorithm can improve the security of password storage, but still not enough security. Hackers usually after the invasion to save the password database, he will randomly guess a password to generate a hash value using a hash algorithm. If the hash value exists in the database, then he would guess a user's password. If you do not guess it does not matter, he can randomly guessing a password to try again. In fact hackers crack the code in order to improve efficiency, they will advance to calculate the hash value of a large number of various hashing algorithm corresponding password, and the password and the corresponding hash values ​​are stored in a table (often referred to this form rainbow table). When crack the code only needs to match the rainbow table can be prepared in advance. So now the hackers to break the encryption with only just over a password hashing algorithm in fact is effortless.

Salt improve security

In response to hackers crack passwords using rainbow tables, we could start to clear text passwords salt, then add salt after the password hashing algorithm used to encrypt. The so-called salt is a random string, add salt to the plaintext password is the plaintext password and a random string spliced ​​together. As the salt should be used when password verification, the hash value is usually salt and passwords are stored together.

Salted hash algorithm to encrypt the password, it is noteworthy. We want to make sure that only add salt to each password to a random, rather than sharing the same password for all of salt. If all share a unified password salt, when the hacker guessed the salt, he can generate a rainbow table for the salt, and then we hash value after the salt to go with his new rainbow table match can break password.

Although the algorithm can effectively deal with salted rainbow table cracking method, but its security level is not high, this is due to the characteristics of the resulting hash algorithm. Hash algorithm was originally used to ensure data integrity during network transmission data. When we have a packet transmitted over the network, we attach a hash value corresponding to the packet at the end of the packet at transmission. When receiving data, we once again generates a hash value using the same algorithm based on the received packet. If the hash value and the hash value is received from the network to the same, it would prove that the problem does not occur in data transmission. In order to reduce latency network transmission, we want to try to hash algorithm is faster, reducing the time data validation as possible. Therefore, when the hashing algorithm design, fast and efficient is a very important indicator. Currently in the general configuration of the computer, time-consuming mainstream hashing algorithm at the level of microseconds, which means we can calculate the hash value of nearly a million times in less than a second class.

Fast and efficient hashing algorithm to encrypt brought a lot of challenges, because the security of the encryption algorithm should be a hacker to crack the algorithm is extremely difficult, time-consuming and compute the hash value is very short, hackers can go by Violence after the break with salt hashing algorithm to encrypt passwords. As mentioned earlier, a hash value, and the salt normally stored together. So a hacker can use salt for each two simple violence law crack the code.

First, using brute-force method. Hackers generate a password, and then spliced together salt hash value is calculated. If the hash value of the hash value and the database is consistent, then the password was cracked. If not, the next attempt in progress. This method is very effective for low-level password. For example, 6 -bit full digital passwords were only possible in one million. This means that any 6 -bit digital-only password even after the salt can be cracked in a matter of seconds. Although crack the password with a high level of Violence Act (such as both numbers, passwords uppercase and lowercase letters and special characters) currently requires a lot of time, but followed Moore's Law of computing power continues to increase, it seems very time-consuming operation today It may be completed very quickly in the future. In addition, in recent years, the rapid development of cloud computing, but also makes hackers can use a very cheap price to rent a large number of computers to facilitate their parallel crack the code, so hackers crack the low-cost and efficient high-level code as possible.

Second, hackers have a large collection of commonly used passwords from breaches in the previous password. For each salt, a hacker can choose from these cyclically reused in a password, add salt and then compute the hash value. Therefore, even if these commonly used passwords salt is also very easy to crack.

With BCrypt or PBKDF2 more difficult to crack

In order to cope with brute force, we need to be very time-consuming and not very efficient hash algorithm. BCrypt algorithm came into being. We can use BCrypt generate a hash algorithm then add salt to the password. Bcrypt biggest feature is the number of times we can repeat the calculation of the parameter settings. The number of apparent double-counting of the more time-consuming longer. If you need to calculate a hash value takes 1 seconds or more, then the hackers crack passwords using windfall law will no longer be possible. To the aforementioned 6 Wei pure digital password, for example, require time-consuming to crack a password 11.5 days, not to mention the high level of security password.

There are open source projects ( http://bcrypt.sourceforge.net/ ) implements BCrypt algorithm and is widely used in the industry. If you are a .NET programmer, you may find the current .NETFramework also does not include BCrypt implementation. In this case there are two options. First, there are already some open source projects use C # to achieve a BCrypt algorithm, we can directly use. If there are concerns about these security implementation, we can also choose and BCrypt similar PBKDF2 . PBKDF2 same number of iterations may be set to extend the parameter calculated by the calculation time. In .NETFramework , the type Rfc2898DeriveBytes realized PBKDF2 function.

summary

Securely store passwords is not an easy thing. Although there are many companies using salted hashing algorithm to deal with rainbow tables to crack method, but this method is not secure enough. Since hashing algorithms are very efficient, time-consuming hash value is calculated in the microsecond level, so hackers can crack the code by Violence Act. A recommended way to use BCrypt or PBKDF2 extension of time to calculate a hash value, thereby increasing the difficulty of cracking passwords. In addition, not every company needs its own project to store the password. Our other option is to use OpenID to delegate user calibration work to third-party companies can rely on.

Original Address: https: //blog.csdn.net/cadcisdhht/article/details/19282407

Guess you like

Origin www.cnblogs.com/jpfss/p/11024665.html