PYTHON-LDAP Implementing a login case

Source: Internet
Author: User
Tags ldap

1Ldap_config = {2     'Ldap_path':'ldap://xx.xx.xx.xx:389',3     'base_dn':'ou=users,dc=ledo,dc=com',4     'Ldap_user':'uid=reporttest,ou=users,dc=ledo,dc=com',5     'Ldap_pass':'111111.0',6     'Original_pass':'111111.0'7 }8 9Ldap_message = {Ten0:0,#' OK ' One1:1,#' User name or password error ' A2:2,#LDAP Authentication exception ' - } -  the ImportLDAP - ImportBase64 - ImportHashlib -  fromConfig_messageImportLdap_config, Ldap_message +  -  + classLdap_api (object): A  at_ldap_path = ldap_config['Ldap_path'] -_BASE_DN = ldap_config['base_dn'] -_ldap_user = ldap_config['Ldap_user'] -_ldap_pass = ldap_config['Ldap_pass'] -_original_pass = ldap_config['Original_pass'] -  in     #connecting to an LDAP server -     def __init__(self): to  +         Try: -Self.ldapconn =ldap.initialize (Self._ldap_path) theSelf.ldapconn.protocal_version =LDAP. VERSION3 * Self.ldapconn.simple_bind (Self._ldap_user, Self._ldap_pass) $ Panax Notoginseng         exceptLDAP. Ldaperror, E: -             Printe the  +     #Verifying user logon A     defLdap_check_login (self, username, password): the  +obj =Self.ldapconn -SearchScope =LDAP. Scope_subtree $         #searchfilter = ' (& (cn= ' +username+ ') (userpassword= ' +password+ ')) ' $Searchfilter ='uid='+username -  -         Try: theObj.search (SELF._BASE_DN, SearchScope, Searchfilter, None)#id--2 -             #The ID calculated in the previous step is evaluated belowWuyiResult_type, Result_data = Obj.result (2, 0) the             ifResult_type! =LDAP. Res_search_entry: -                 return{'Status': Ldap_message[1],'Data':"'} WuDIC = result_data[0][1] -L_realname = dic['SN'][0] AboutL_password = dic['UserPassword'][0] $Md_password =ldap_api.hash_md5 (password) -             ifL_passwordinch(password, md_password): -                 return{'Status': Ldap_message[0],'Data': L_realname} -             Else: A                 return{'Status': Ldap_message[1],'Data':"'} +         exceptLDAP. Ldaperror, E: the             return{'Status': Ldap_message[2],'Data':"'} -  $ @staticmethod the     defhash_md5 (data): theMD =hashlib.md5 () the md.update (str (data)) theA =md.digest () -b ='{MD5}'+Base64.b64encode (a) in         returnB

Link http://blog.csdn.net/shanliangliuxing/article/details/8266267

PYTHON-LDAP Implementing a login case

Related Article

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.