|
|
@@ -0,0 +1,60 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+session_start();
|
|
|
+
|
|
|
+function passwd_error($message) {
|
|
|
+ $_SESSION['message'] = $message;
|
|
|
+ header('Location: formpasswd.php');
|
|
|
+ exit();
|
|
|
+}
|
|
|
+
|
|
|
+if (!isset($_SESSION['user'])) {
|
|
|
+ header('Location: signin.php');
|
|
|
+ exit();
|
|
|
+}
|
|
|
+
|
|
|
+if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
|
|
+ header('Location: signin.php');
|
|
|
+ exit();
|
|
|
+}
|
|
|
+
|
|
|
+if (!isset($_POST['password_current'], $_POST['password'], $_POST['password_conf'])) {
|
|
|
+ header('Location: signin.php');
|
|
|
+ exit();
|
|
|
+}
|
|
|
+
|
|
|
+$passwd = $_POST['password'];
|
|
|
+$passwd_conf = $_POST['password_conf'];
|
|
|
+$current_password = $_POST["password_current"];
|
|
|
+
|
|
|
+if ($passwd != $passwd_conf) {
|
|
|
+ passwd_error("Passwords do not match");
|
|
|
+}
|
|
|
+
|
|
|
+if (strlen($passwd) < 8) {
|
|
|
+ passwd_error("Password too short (min 8 chars)");
|
|
|
+}
|
|
|
+
|
|
|
+$ini = parse_ini_file('includes/config.ini');
|
|
|
+
|
|
|
+try {
|
|
|
+ $ldapconn = ldap_connect($ini['hostname'], $ini['port']);
|
|
|
+ ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
|
|
+ ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
|
|
|
+} catch (Exception $e) {
|
|
|
+ die ('ERROR: ' . $e->getMessage());
|
|
|
+}
|
|
|
+
|
|
|
+$dn = "uid=" . ldap_escape($_SESSION['user']) . ',' . $ini["binddn"];
|
|
|
+$ldap_bind = ldap_bind($ldapconn, $dn, $current_password);
|
|
|
+
|
|
|
+if ($ldap_bind) {
|
|
|
+ if (ldap_exop_passwd($ldapconn, $dn, "",$passwd)) {
|
|
|
+ header('Location: home.php');
|
|
|
+ exit();
|
|
|
+ } else {
|
|
|
+ passwd_error("A problem occured, contact admins");
|
|
|
+ }
|
|
|
+} else {
|
|
|
+ passwd_error("Wrong current password");
|
|
|
+}
|