Added verify_password(dn, password) method

master
nanu2 2014-09-23 16:02:20 +02:00
parent e74b09bb50
commit efd56e6bac
3 changed files with 33 additions and 7 deletions

View File

@ -1,25 +1,35 @@
Changelog Changelog
--------------- ---------------
0.1.5 0.2.0
+++++ +++++
- Added escape_filter_chars() to filter the filter **Improvements**
- Added verify_password(dn, password) method
**Bugfixes**
- Added escape_filter_chars() to filter (sanitize) the filter
- Override of cidicts __getitem__ so that user.attrs['nonexistent'] won't raise an exception, but instead returns an empty list - Override of cidicts __getitem__ so that user.attrs['nonexistent'] won't raise an exception, but instead returns an empty list
0.1.3 and 0.1.4
+++++++++++++++
- Wrestling with pypi (needs a new version number even if you've made a mistake by uploading rubbish)
0.1.2 0.1.2
+++++ +++++
- README.md to README.rst (pypi should show a nice README as well) - Converted README.md to README.rst (pypi should show a nice README as well)
0.1.1 0.1.1
+++++ +++++
**Bugfixes**
- Fixed pretty print of binary attribute - Fixed pretty print of binary attribute
- Fixed ldap.get sizelimit=1 exception for now - Fixed ldap.get sizelimit=1 exception for now (come back to this later)
- Added try catch to api - Added try catch to api
0.1 0.1.0
+++ +++++
- Initial version, have to start somewhere - Initial version (have to start somewhere)

View File

@ -21,6 +21,7 @@ class Connection(object):
def search(self, search_filter): def search(self, search_filter):
"""Get list of objects that match the search_filter """Get list of objects that match the search_filter
:param search_filter: filter to find the objects :param search_filter: filter to find the objects
:return: list of LdapperObjects (or empty list) :return: list of LdapperObjects (or empty list)
""" """
@ -83,6 +84,15 @@ class Connection(object):
result = self.get_values(dn, attr) result = self.get_values(dn, attr)
return result[0] return result[0]
def verify_password(self, dn, password):
try:
test_conn = ldap.initialize(self.ldap_url)
test_conn.simple_bind_s(dn, password)
test_conn.unbind_s()
return True
except ldap.LDAPError:
return False
def close(self): def close(self):
self.conn.unbind_s() self.conn.unbind_s()

View File

@ -122,5 +122,11 @@ sn: Doe
user = self.ldap.get_by_dn(self.new_dn) user = self.ldap.get_by_dn(self.new_dn)
self.assertEqual(user.attrs['mobile'], ['9876543210']) self.assertEqual(user.attrs['mobile'], ['9876543210'])
def test_verify_password(self):
self.assertEqual(self.ldap.verify_password(self.bind_dn,
self.password), True)
self.assertEqual(self.ldap.verify_password(self.bind_dn,
'wrong_password'), False)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()