Translation: 晨 辉
24/04/2000
There are often readers to ask, how to use JavaScript on its site to ensure that the password when the user logs in will not leak. For such a problem, my first reaction is to tell them to use SSL (Secure Socket Society Amission). For example, SSL is the best solution for Web applications with higher security requirements. However, there is also a considerable part of the developer, and their web application is not high, so they do not want visitors to log in with SSL.
Web applications generally use a technique called Session State Management to track and manage mutual activity between browsers and servers. Because each browser browsing requires independently relative to other browsers (as defined in Hypertext Transfer Protocol), web applications must use certain techniques, such as cookie, hidden table fields, or rewrite URLs, They recognize the server with a separate session with a browser. Most server-side programming environments (such as ASP, PHP, ColdFusion, etc.) use cookies.
The problem with session status management is fundamentally unsafe. These cookies, form values, or URLs that are used to manage session states, or the hackers can intercept them on the way. Once the interception is successful, hackers can use this information to force the user session.
In most server-side scripts, you can take some measures to reduce this type of leakage. For example, you can set a short period of use for cookies to apply "difficult expectations" information. However, the safest solution is still using SSL. Using SSL, regardless of user password, or session status information is protected.
If you don't use SSL, you can ask users to re-authenticate each sensitive page in your application. However, from the user's perspective, this way will not be too troublesome. In short, you must know how high your users are willing to bear how high the risks are willing to bear. If the risk of password leaks is too high, you need to use SSL to build applications. If you can't use SSL, you can use the MD5-based login mode. It can at least protect your user's password from leakage. In addition, a server-side script preparation technique that prevents session status information is stolen.
Typically, if a user does not use SSL login (ie, the original http), then from the time of leaving the browser until the target network server, the user password is in a non-protected exposure, as shown in the chart in the following page. .
However, we can use an irreversible function to develop a login scheme, which will not expose the user's password using this solution. The function is a correspondence between the elements of the collections, and in the function from the set A to the set B, each element is in B has a unique element corresponding to it. The irreversible function is difficult to reverse in the calculation - that is, one element in a given collection B, it is difficult to determine which element in the collection A corresponds to it.
This is the better than a shredder. It is easy to put files in a shredder. But in turn, if you want to refract strain after the destruction, it can be difficult.
Using MD5 solution
One of the most popular non-reversible functions applications today is the MD5 algorithm developed by Ronald Rivest. Ronald Rivest is also one of the developers of the famous RSA (Rivest, Shamir, ADELMAN) encryption algorithm. The MD5 algorithm can generate a 16-byte size "digital fingerprint" for any length of information. This information can be a string, a file, a text stream, or any other form of byte sequence. A detailed description of the MD5 algorithm in RFC 1321.
We want to develop a login method using the MD5 algorithm to protect user passwords from a browser to the web server.
When a user files a login request for a web application, its web server will give the user a login form. This is a table with a random generated value. The random generating value is randomly selected from a billion-reserved value space from a billion to the value.
The user enters his or her username and password in the login form, and the user-end script adds a random value to the password, and then calculates the results with the MD5 irreversible algorithm. Replace the original password with the calculated value. I refer to this value as MD5 password.
Finally, the user end script sends the username and the MD5 password to the web server. Because anyone is transmitted between the browser and the server, anyone cannot obtain the original password entered by the user.
After receiving the username and MD5 password, the web server will perform the same operation as the user browser. It gives the user password (extracted from the protected area of the server) (ie the random value sent to the user) and the correct MD5 password value is calculated. The web application is then compared to the value of this value and it collected from the browser. If the two values are equal, the web application generates a server-side session variable to prove that this user is correct.
Speaking here, you may quit the necessity of using a random value. In fact, this random value is used to prevent re-attack. If only the original user password passes MD5, then the corresponding MD5 password will always be the same value. Hackers can also log in to network applications as long as they intercept MD5 passwords. After using the random value, the MD5 password generated each time you log in is unique, so that the appearance of the above problems is avoided.
JavaScript implementation b>
The login scheme that implements the MD5 encrypted in JavaScript is relatively easy. Paul Johnston's site provides you with rich information realized by the MD5 algorithm. Other information about MD5 can be found in this site. Please copy the code to a text file and name MD5-JS.txt.
We will complete the server-side script in the ASP environment (because the ASP supports JScript-Microsoft version of JavaScript). You can write a language using any server-side script, but you must translate the MD5 algorithm into the language you choose.
The following is a login table login.asp implemented in an ASP environment. You can use online analog login analog user name Jason, the user password is F2 # 5% RSQ.
<% @ Language = "JScript"%>
<% Session ("SharedValue" = Math.random (). Tostring ()%>