Guest User

Untitled

a guest
Feb 11th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. # LDAP is case-insensitive hence no need to normalize username here
  2.  
  3. def authenticate_ldap(username, password):
  4. username = ldap.filter.escape_filter_chars(username)
  5. password = ldap.filter.escape_filter_chars(password) # May cause problem with some passwords. Please test this.
  6. base_dn = settings.LDAP_CURRENT_YEAR_DN
  7. user_filter = "uid=" + username
  8. user_dn = ",".join([user_filter, base_dn])
  9. connect = ldap.initialize(settings.LDAP_URI)
  10. try:
  11. # if authentication successful, return the full user data
  12. connect.bind_s(user_dn, password)
  13. result = connect.search_s(base_dn, ldap.SCOPE_SUBTREE, user_filter)
  14. connect.unbind_s()
  15. if len(result) == 1:
  16. return result[0]
  17. else:
  18. return False
  19. except ldap.LDAPError:
  20. connect.unbind_s()
  21. return False
  22.  
  23.  
  24. chs = ['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
  25. chl = ['Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M']
  26. chn = ['0','1','2','3','4','5','6','7','8','9']
  27. chsp = ['!','(',')','-','.','_','`','~','@','#']
Add Comment
Please, Sign In to add comment