From 5a5fa95b0d4a3b70c43c906710b4ce095683cfe4 Mon Sep 17 00:00:00 2001
From: nd <git@notandy.de>
Date: Sun, 12 Jul 2020 01:26:32 +0200
Subject: [PATCH] add support to change passwords

---
 uffd/user/models.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/uffd/user/models.py b/uffd/user/models.py
index a7ca6358..8d889a1f 100644
--- a/uffd/user/models.py
+++ b/uffd/user/models.py
@@ -1,6 +1,7 @@
 import string
 
 from ldap3 import MODIFY_REPLACE, HASHED_SALTED_SHA512
+from ldap3.utils.hashed import hashed
 from flask import current_app
 
 from uffd import ldap
@@ -63,12 +64,10 @@ class User():
 				'cn': [(MODIFY_REPLACE, [self.displayname])],
 				'mail': [(MODIFY_REPLACE, [self.mail])],
 				}
+			if self.newpassword:
+				attributes['userPassword'] = [(MODIFY_REPLACE, [hashed(HASHED_SALTED_SHA512, self.newpassword)])]
 			dn = ldap.uid_to_dn(self.uid)
 			result = conn.modify(dn, attributes)
-		if result:
-			if self.newpassword:
-				print(self.newpassword)
-				conn.extend.standard.modify_password(user=dn, old_password=None, new_password=self.newpassword, hash_algorithm=HASHED_SALTED_SHA512)
 		return result
 
 	def get_groups(self):
-- 
GitLab