Ldap+flask+python2 to achieve unified authentication inside those coded pits

Source: Internet
Author: User
Tags ldap

First want to vomit trough, directly take over other people's project, and is after four or five hands of the project, is how a pain. Two or three sets of code Django, flask, Tornado Everything, code, break the finger can be a number of full English comments, a few servers did not transfer clearly, all are asked to say, the normal should work together for a period of time, and then the egg, after the handover will not respond. The first half of the month to read the code, to figure out what others thought, cool ~

These two days to kill a problem, the project background is to achieve an account password login to multiple systems, a colleague changed the password after the other system can log on, only one system has not been logged. Password with Chinese punctuation, a change of password test, sure enough Chinese punctuation mark too. But not all Chinese punctuation, some special characters can not be too. Cater to front end, server two times authentication, blacklist and whitelist card, regular as follows:

 #   regular judgment Chinese characters  #  pattern = u" [\ Uff1f\uff01\uff0c\u0026\uff1b\uff1a\uff08\uff09\u3008\u3009\u300e\u300f\u300c\u300d\ufe43\ufe44\u3014\u3015\ u2026\uff5e\ufe4f\uffe5><]+ " #   Verify password 8-16 digits, uppercase and lowercase letters, half-width characters 3 combinations  pattern =  ^ (?:(? =.*[0-9].*) (? =.*[a-za-z].*) (? =.*[,\.#% ' \+\*\-:;^_ ' &| " @=~{}\[\]\ (\) \$<>\?/!]. *)) [, \.#% ' \+\*\-:;^_ ' &| " @=~{}\[\]\ (\) \$<>\?/!0-9a-za-z]{8,16}$    

Obviously this only allows users to re-change the password, the experience is not very good.
Another way of thinking, why change the password other systems can pass, only one however, it is compatible with the system. Most of the probability involved in Chinese is related to coding, and a friend using Python should be coded in a pit.
There are 3 places to troubleshoot password changes:
  1. Change the password
defModify_password (conn, e-mail, New_password, old_password=None):ifOld_password isNone andConn isNone:conn=Bind_ad (ADMIN, ADMINPD) conn.search (DC,'(& (Objectclass=person) (Mail={email}))'. Format (email=email)) if  notconn.entries:return "'User=Conn.entries[0]Print('User', user) DN=user.entry_dnifSUPERVISOR:#DN = user.entry_dn.encode (' raw_unicode_escape ')        #change here to Utf-8DN = User.entry_dn.decode ('Utf-8') Re=Conn.extend.microsoft.modify_password (DN, New_password, Old_password)returnRe


 2. Verify that the old password is not bound to LDAP
# knowing the original password change password will detect if the old password is bound to LDAPold_password = Passwd_reqparse.parse_args (). OldPassword#  conn = Bind_ad (email, old_password)#  here instead utf-8conn = bind_ad (email, old_password.encode ( ' Utf-8 '))


3. At the time of certification
#File Header AddImportsysreload (SYS) sys.setdefaultencoding ('UTF8')#default ASCII code, changed to UTF8defParse_para (json_data):"""Resolve user-entered account password"""Password= Json_data.get ('Password') Password_utf8= Password.encode ('Utf-8')    #return code after transcoding    returnResponse_json, BusinessName, email, Password_utf8, NAMEPW, method

Recommend a useful tool to view LDAP information:ldapbrowser

Unicode conversion Tool:http://tool.chinaz.com/tools/unicode.aspx

Ldap+flask+python2 to achieve unified authentication inside those coded pits

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.