Browse Source

Hash password

command-line
uid 2 years ago
parent
commit
86e8ed669b
  1. 6
      src/phi/ldap/user.py
  2. 2
      test/test_ldap.py

6
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)

2
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)

Loading…
Cancel
Save