PfSense Firewall with a captive portal
Server 2008 running AD for users to authenticate with Radius through the Captive Portal.
Another server running IIS Web Server with PHP 5.3.
Our goal is to make a PHP script that allows people to change their password first time they logon, as the captiveportal does not
support the "Users must change password at first logon" option.
we got a PHP script already, but we are stuck at the ldap_modify action for the password.
Any help is appreciated.
Code looks like this:
----------------------------------------------------
PHP Code:
<?php $message = array();
function changePassword($user,$oldPassword,$newPassword,$newPasswordCnf){ global $message;
// echo "<pre>";print_r($records); /* error if found more than one user */ /* if ($records["count"] != "1") { $message[] = "Brugere fundet:" . $records["count"]; $message[] = "Error E100 - Wrong user."; return false; }else { $message[] = "Found user <b>".$records[0]["cn"][0]."</b>."; } */
/* try to bind as that user */ // if (ldap_bind($con, $records[0]["dn"], $oldPassword) === false) { if (ldap_bind($con, $user, $oldPassword) === false) { $message[] = "Error E104 - Current password is wrong."; return false; } else { }
if ($newPassword != $newPasswordCnf ) { $message[] = "Error E101 - New passwords do not match! "; return false; } if (strlen($newPassword) < 8 ) { $message[] = "Error E102 - Your new password is too short! "; return false; } if (!preg_match("/[0-9]/",$newPassword)) { $message[] = "Error E103 - Your password must contain at least one digit. "; return false; } if (!preg_match("/[a-zA-Z]/",$newPassword)) { $message[] = "Error E103 - Your password must contain at least one letter. "; return false; }
if (ldap_modify($con,$user,$entry) === false){ $message[] = "E200 - Your password cannot be change, please contact the administrator."; } else { $message[] = " Your password has been changed. "; //mail($records[0]["mail"][0],"Password change notice : ".$user,"Your password has just been changed."); }
I've done a bit of work with AD and PHP and when working with them I always stayed away from changing user passwords cos I was under the impression that you had to use LDAPS rather than LDAP for AD to accept a password change via LDAP_modify. Dont take my word on this as I might be wrong.
But if LDAPS is required then you need PHP compiled with SSL support and then u have all the trouble of that... Then I'm not sure if you have to create the certificate from the AD server too.
But if you need help changing AD values other than the password I might be able to help. Remember by default a user doesnt have permission to change their own personal details in AD so many things cannot be modified by their own user credentials. You will need to modify AD permssions to give user access to modify their SELF details.