Modified the Django source code.

Source: Internet
Author: User

Generally, the system requires that the simplest logon feature always has a password-remembering function. Websites like Douban automatically remember the password and do not have a chance for users to choose from. However, the loss of its password will not cause too much loss, and I don't know if it uses the Django framework, so it's hard to say. However, if he wants to make online sales in the future, this problem must be solved.

In Django's implementation, a configuration in the configuration file determines whether to enable the Remember password function, and is enabled by default. If this configuration is changed, it becomes the cookie of the browser lifecycle, however, there is no way to remember the password. You can only select one of them.

Later I considered an article on the Internet.ArticleUnder the Django directory, contrib/sessions/has a middleware. py, which is the implementation process of the session. In its processresponse, there is a judgment. If this configuration is the browser lifecycle, a cookie with expired as none will be written to the client. Otherwise, a cookie with an expiration time of two weeks will be written.

To simplify the modification process (because it will soon be available in Version 1.0, I am afraid I will change it again), I made a lazy modification: take the value of the 'issaved' variable in the session directly here. If it is true, the two-week cookie is also saved. Otherwise, the default value is used. Then, when the user logs on, if the user selects this box, the variable "true" will be added to the session. Everything is OK, and only three lines need to be changed.Code. But the trouble is that every time you update Django, You have to modify it, and every time you migrate the server environment. If you forget it once, you will have to remember that the password will fail.

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.