From 86e8ed669ba816744b09834371158fd0b76801fa Mon Sep 17 00:00:00 2001 From: User Identifier Date: Sat, 10 Oct 2020 12:59:41 +0200 Subject: [PATCH] Hash password --- src/phi/ldap/user.py | 6 ++++-- test/test_ldap.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/phi/ldap/user.py b/src/phi/ldap/user.py index 984771f..03ed4e5 100644 --- a/src/phi/ldap/user.py +++ b/src/phi/ldap/user.py @@ -1,4 +1,5 @@ -from ldap3 import ALL_ATTRIBUTES +from ldap3 import ALL_ATTRIBUTES, HASHED_SALTED_SHA +from ldap3.utils.hashed import hashed from phi.ldap.utils import get_response, make_user_dict, add_entry, delete_entry from phi.logging import get_logger @@ -50,6 +51,7 @@ def get_all_users(client): def add_user(client, uid, cn, sn, mail, password): dn = 'uid={},ou=Hackers,{}'.format(uid, client.base_dn) + hashed_password = hashed(HASHED_SALTED_SHA, password) attributes={ 'objectClass': [ @@ -60,7 +62,7 @@ def add_user(client, uid, cn, sn, mail, password): 'cn': cn, 'sn': sn, 'mail': mail, - 'userPassword': password # TODO: use hashed password + 'userPassword': hashed_password } add_entry(client, dn, attributes) diff --git a/test/test_ldap.py b/test/test_ldap.py index 0cf7a2b..0947323 100644 --- a/test/test_ldap.py +++ b/test/test_ldap.py @@ -92,6 +92,8 @@ def test_add_to_group(ldap_client): assert len(group_members) == 2 assert user['uid'] in group_members + # print(group_members) + # print(user) delete_user(client, user)