1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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 Passwortbesttigung 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 auswhlen */
display: block;
float: left;
width: 200px; /* Breite.*/
}
form br { /* Alle Zeilenumbrche in Formularen auswhlen */
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 besttigen:</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>
|