@@ -398,4 +398,49 @@ public function getEndDate($entry, $pwdPolicyConfiguration) : ?DateTime {
398398 return $ enddate ? $ enddate : null ;
399399 }
400400
401+ public function computePassword ($ ldapInstance , $ dn , $ password , $ hash , $ hash_options , $ use_exop_passwd ) : string {
402+
403+ # If using the password extended operation, compute the password
404+ if (!$ use_exop_passwd ) {
405+ if ($ hash === "auto " ) {
406+ $ old_password_hashed = $ ldapInstance ->get_password_value ($ dn , "userPassword " );
407+ $ hash = \Ltb \Password::get_hash_type ($ old_password_hashed );
408+ }
409+ $ password = \Ltb \Password::make_password ($ password , $ hash , $ hash_options );
410+ }
411+ # If using the password extended operation, just send the cleartext password
412+
413+ return $ password ;
414+ }
415+
416+ public function changePasswordData ($ ldapInstance , $ dn , $ userdata , $ password , $ oldpassword , $ who_change_password , $ use_exop_passwd , $ use_ppolicy_control , $ custom_pwd_field_mode , $ custom_pwd_attribute , $ ad_options ) : array {
417+
418+ list ($ error_code , $ error_msg , $ ppolicy_error_code ) = array (null , null , null );
419+
420+ if ( $ custom_pwd_field_mode ) {
421+ $ pwd_attribute = $ custom_pwd_attribute ;
422+ } else {
423+ $ pwd_attribute = "userPassword " ;
424+ }
425+
426+ if ($ use_exop_passwd ) {
427+ list ($ error_code , $ error_msg , $ ppolicy_error_code ) = $ ldapInstance ->change_password_with_exop ($ dn , $ oldpassword , $ password , $ use_ppolicy_control );
428+ if ( $ error_code == 0 )
429+ {
430+ list ($ error_code , $ error_msg ) = $ ldapInstance ->modify_attributes ($ dn , $ userdata );
431+ }
432+ } else {
433+ # Else just replace with new password
434+ $ userdata [$ pwd_attribute ] = $ password ;
435+
436+ if ( $ use_ppolicy_control ) {
437+ list ($ error_code , $ error_msg , $ ppolicy_error_code ) = $ ldapInstance ->modify_attributes_using_ppolicy ($ dn , $ userdata );
438+ } else {
439+ list ($ error_code , $ error_msg ) = $ ldapInstance ->modify_attributes ($ dn , $ userdata );
440+ }
441+ }
442+
443+ return array ( $ error_code , $ error_msg , $ ppolicy_error_code );
444+ }
445+
401446}
0 commit comments