Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. # -*- coding: UTF-8 -*-
  2.  
  3. import ldap
  4.  
  5. def validate_ldap_user(user_name, user_pwd):
  6. l = ldap.initialize(_LDAP_URL)
  7. try:
  8. l.protocol_version = ldap.VERSION3
  9. l.simple_bind_s(user_name, user_pwd)
  10. return True, ""
  11. except ldap.INVALID_CREDENTIALS:
  12. error_msg = "Your username or password is incorrect."
  13. except ldap.LDAPError as e:
  14. if hasattr(e, 'message') and type(e.message) == dict and e.message.has_key('desc'):
  15. error_msg = e.message['desc']
  16. else:
  17. error_msg = e
  18. l.unbind_s()
  19.  
  20. return False, error_msg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement