Design and Implementation of Secure Login System

Source: Internet
Author: User
Tags hmac

For Web applications, secure login is very important. However, at present, most web systems send logon passwords in plain text, which can be easily listened to by intruders. Of course, it is a good method to implement secure connections through SSL, but in many cases we cannot set the server as a web server with SSL. Therefore, if you add a secure logon mechanism to the logon system, you can achieve secure logon on a Web server without SSL.

To achieve secure login, you can use the following two methods: asymmetric encryption algorithm and HMAC algorithm. The following two methods are discussed respectively.

Among asymmetric encryption algorithms, RSA and ECC are the most commonly used algorithms. To use asymmetric encryption algorithms for secure login, the server must first generate a public key and private key when the client requests a login page from the server, the Public Key is then transmitted along with the logon page to the client browser. After you enter the user name and password and click log on, the JavaScript on the logon page calls the asymmetric encryption algorithm to encrypt the user name and password with the public key. Then, submit it to the server, and then the server uses the private key for decryption, and then compares it with the username and password in the database. If the password is the same, the logon is successful. Otherwise, the logon fails.

It seems very simple, but there are several problems here. Currently, the 1024-2048-bit key in the RSA algorithm is considered safe. If the key length is smaller than this length, it is considered to be cracked. However, such a length exceeds the numerical operation range allowed by the programming language itself, and a large number operation needs to be performed through simulation. On the web system client, if Javascript is used to simulate large numbers, the efficiency will be very low. Therefore, if such a key is used on the client to encrypt data, many browsers will issue a warning that execution takes too long to stop. However, decryption or key generation takes longer than encryption. Although decryption and key generation are performed on the server side, if the server side is a scripting language such as PHP and ASP, it will be difficult for them to do the same job. The key length requirements of the ECC algorithm are lower than those of the RSA algorithm. The 160-bit key length in the ECC algorithm is considered to be equivalent to the 1024-bit key length in the RSA algorithm. Although it still involves the simulation of large numbers, the calculation of the key length of the ECC algorithm is acceptable, but the ECC algorithm is much more complex than the RSA algorithm, therefore, it is very difficult to implement it.

Symmetric encryption algorithms are much faster than asymmetric encryption algorithms. Why not use symmetric encryption algorithms? Because the symmetric encryption algorithm requires the data sender and receiver to share a key, if the sender of the web system, that is, the client browser, needs to encrypt the password, you need to obtain the key from the server first, but the transfer of the key may be monitored. If the encrypted data is also monitored at the same time, intruders can directly decrypt the encrypted information by using the listening key.

However, if we do not use the encryption algorithm but use the hash algorithm to process the logon password, we can avoid directly decrypting the original text, however, if MD5 or sha1 is used directly to process and submit the logon password, once the intruder monitors the hash password, the original text does not need to be decrypted, you can directly submit the listened data to the server for intrusion. At present, the MD5 algorithm has been cracked, and The sha1 algorithm has been proved to be cracked theoretically. Even if an offline collision is used, the password equivalent to the original password can be found. Therefore, it is not feasible to use MD5 or sha1.

However, if the key is added to the hash algorithm, the situation is different. The HMAC algorithm is just like this. Let's take a look at how to use the HMAC Algorithm for secure login. When the client requests a login page from the server, the server generates a random string and sends it together with the login page to the client browser. After the user enters the username and password, the password uses MD5 or sha1 to generate hash values as the key, and the random string sent by the server as the message data for HMAC calculation. Then, submit the result to the server. The reason for hashed passwords entered by users and then used them as keys instead of keys is to ensure that the keys are long enough and not long enough. After the server receives the data submitted by the client, it performs the same operation on the random string stored on the server and the user password, and then compares the results. If the results are consistent, the login is successful, otherwise, the logon fails.

The random string sent by the server is different when the client requests each time. Therefore, even if the intruders listen to the random string and the encrypted submitted data, it cannot submit the same data again for verification. In addition, the key cannot be calculated from the data monitored, so the login information cannot be forged.

Therefore, it is most feasible to use the HMAC algorithm to implement secure login to the system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.