国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python ldap實現登錄實例代碼

Python ldap實現登錄實例代碼

2020-09-09 09:48張瑜 Python

今天給大家分享python idap實現登錄的實例代碼,代碼簡單易懂,需要的朋友一起看看吧

下面一段代碼是小編給大家介紹的Python ldap實現登錄實例代碼,一起看看吧

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
ldap_config = {
  'ldap_path': 'ldap://xx.xx.xx.xx:389',
  'base_dn': 'ou=users,dc=ledo,dc=com',
  'ldap_user': 'uid=reporttest,ou=users,dc=ledo,dc=com',
  'ldap_pass': '111111.0',
  'original_pass': '111111.0'
}
ldap_message = {
  0: 0, #'ok'
  1: 1, #'用戶名或密碼錯誤'
  2: 2, #ldap驗證異常'
}
import ldap
import base64
import hashlib
from config_message import ldap_config, ldap_message
class LDAP_API(object):
  _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']
  # 連接ldap服務器
  def __init__(self):
    try:
      self.ldapconn = ldap.initialize(self._ldap_path)
      self.ldapconn.protocal_version = ldap.VERSION3
      self.ldapconn.simple_bind(self._ldap_user, self._ldap_pass)
    except ldap.LDAPError, e:
      print e
  # 驗證用戶登錄
  def ldap_check_login(self, username, password):
    obj = self.ldapconn
    searchScope = ldap.SCOPE_SUBTREE
    # searchFilter = '(&(cn='+username+')(userPassword='+password+'))'
    searchFilter = 'uid=' + username
    try:
      obj.search(self._base_dn, searchScope, searchFilter, None) # id--2
      # 將上一步計算的id在下面運算
      result_type, result_data = obj.result(2, 0)
      if result_type != ldap.RES_SEARCH_ENTRY:
        return {'status': ldap_message[1], 'data': ''}
      dic = result_data[0][1]
      l_realname = dic['sn'][0]
      l_password = dic['userPassword'][0]
      md_password = LDAP_API.hash_md5(password)
      if l_password in (password, md_password):
        return {'status': ldap_message[0], 'data': l_realname}
      else:
        return {'status': ldap_message[1], 'data': ''}
    except ldap.LDAPError, e:
      return {'status': ldap_message[2], 'data': ''}
  @staticmethod
  def hash_md5(data):
    md = hashlib.md5()
    md.update(str(data))
    a = md.digest()
    b = '{MD5}' + base64.b64encode(a)
    return b

原文鏈接:http://www.cnblogs.com/work115/archive/2016/09/30/5923278.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 亚洲视频中文字幕在线观看 | 黄色片子免费观看 | 亚洲精品黄色 | 色综合久久一区二区三区 | 久久久国产一区二区三区 | 国产精品美女久久久久久久网站 | 久久午夜综合久久 | 久久视频国产 | 久久精品中文 | 精品成人一区 | 午夜视频福利在线观看 | 亚洲第一免费播放区 | 婷婷综合一区 | 国产精品久久久久久久久久99 | 国产日韩一区 | 国产精品久久久久久久久久新婚 | 亚洲男人的天堂视频 | 精品性 | 亚洲成人精品久久久 | 在线观看中文字幕 | 亚洲一区二区三区在线播放 | 一区二区免费看 | 国产免费一区二区三区 | 亚洲国产精品成人 | 91成人免费在线观看 | 久久国产精品久久久久久电车 | 免费看亚洲 | 精一区二区 | 天堂色| 精品亚洲免费 | 国产欧美精品一区二区色综合 | 国产综合视频 | 91免费在线视频 | 国产成人在线一区二区 | 一区二区日本 | 亚洲电影一区 | 国产精品久久久久久吹潮 | 香蕉久久av一区二区三区 | 国产欧美日韩二区 | 国产日韩欧美 | 国产在线中文字幕 |