diff options
Diffstat (limited to 'change_password.php.bak')
| -rw-r--r-- | change_password.php.bak | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/change_password.php.bak b/change_password.php.bak new file mode 100644 index 0000000..28347ae --- /dev/null +++ b/change_password.php.bak @@ -0,0 +1,98 @@ +<?php +$hostname = "ldap"; +$port = 389; + +$bind_rdn = "uid=".$_SERVER['PHP_AUTH_USER'].",ou=members,o=ccwn.org,o=CCWNServer"; +$bind_password = $_POST["oldPassword"]; + +$success_msg = null; +$error_msg_old_pw = null; +$error_msg_new_pw = null; + +if ($_POST) { + $ldap_ds = ldap_connect($hostname, $port) or die("Could not connect to LDAP"); + + ldap_set_option($ldap_ds,LDAP_OPT_PROTOCOL_VERSION,3); + + $connected = @ldap_bind($ldap_ds, $bind_rdn, $bind_password); + + if ($connected) { + if ($_POST["newPassword"] == $_POST["oldPassword"]) { + $error_msg = "Das neue Passwort muss sich vom alten Passwort unterscheiden"; + } else if (0 < preg_match("/".$_SERVER["PHP_AUTH_USER"]."/i", $_POST["newPassword"])) { + $error_msg = "Das neue Passwort darf den Benutzernamen nicht enthalten"; + } else if ($_POST["newPassword"] != $_POST["newPassword2"]) { + $error_msg_new_pw = "Die Passwortbestätigung stimmt nicht mit dem neuen Passwort überein"; + } else { + $attributes["userPassword"] = $_POST["newPassword"]; + $modified = ldap_modify($ldap_ds, $bind_rdn, $attributes); + if ($modified) { + $success_msg = "Änderung erfolgreich"; + } else { + $error_msg = "Fehler beim Schreiben der Änderung"; + } + } + + } else { + if (49 == ldap_errno($ldap_ds)) { + $error_msg_old_pw = "Falsches Passwort"; + } else { + $error_msg = "LDAP Error: '".ldap_error($ldap_ds)."'"; + } + } + ldap_close($ldap_ds); +} + + +?> +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> + <title>Change your password</title> + <style type="text/css"> + label, input, select { /* Alle Labels UND Formularelemente auswählen */ + display: block; + float: left; + width: 200px; /* Breite.*/ + } + + form br { /* Alle Zeilenumbrüche in Formularen auswählen */ + clear: left; /* das floating der labels und inputs aufheben */ + } + + input#submit { /* den Submit-Button */ + float: none; + width: auto; + } + </style> + </head> + <body> + <p>Du bist eingeloggt als: <?php echo $_SERVER['PHP_AUTH_USER']; ?></p> + <?php + if (null != $success_msg && null == $error_msg && null == $error_msg_old_pw && null == $error_msg_new_pw) { + echo "<span style=\"color:green;\">".$success_msg."</span><br/>"; + } else if (null != $error_msg) { + echo "<span style=\"color:red;\">".$error_msg."</span><br/>"; + } + ?> + <form name="password_form" action="change_password.php" method="post"> + <label for="name">Altes Passwort:</label> <input type="password" id="oldPassword" name="oldPassword" /> + <?php + if (null != $error_msg_old_pw) { + echo "<span style=\"color:red;\">".$error_msg_old_pw."</span><br/>"; + } + ?> + <br /> + <label for="name">Neues Passwort:</label> <input type="password" id="newPassword" name="newPassword" /><br /> + <label for="name">Neues Passwort bestätigen:</label> <input type="password" id="newPassword2" name="newPassword2" /> + <?php + if (null != $error_msg_new_pw) { + echo "<span style=\"color:red;\">".$error_msg_new_pw."</span><br/>"; + } + ?> + <br /> + <input type="submit" id="submit" /> + </form> + </body> +</html>
\ No newline at end of file |
