preferences文件增加输入栏位(在第一个form之后):
<script>
function submit_check(f){
if (f.txtpassword1.value=="") {
alert("密码1: 不能为空");
f.txtpassword1.focus();
return false;
}
if (f.txtpassword2.value=="") {
alert("密码2: 不能为空");
f.txtpassword2.focus();
return false;
}
if (f.txtpassword1.value != f.txtpassword2.value){
alert("密码: 不匹配");
f.txtpassword1.focus();
return false;
}
}
</script>
<div align="center">
<form method="post" action="save_password.php" onsubmit="return submit_check(this)">
<table width="502" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="502" colspan="3">
<font color=red><?php echo $error; ?></font>
<hr size="1">
</td>
</tr>
<tr>
<td width="125">新密码</td>
<td width="10">:</td>
<td width="367">
<input type="text" name="txtpassword1" maxlength="100" size="40">
</td>
</tr>
<tr>
<td width="125">重复密码</td>
<td width="10">:</td>
<td width="367">
<input type="text" name="txtpassword2" maxlength="100" size="40">
</td>
</tr>
<tr>
<td width="135" colspan="2"> </td>
<td width="367">
<input type="submit" name="Submit" value="修改密码">
</td>
</tr>
</table>
</form>
</div>
新增文件save_password.php:
<?
/*
File name : save_password.php
Version : 1.0.0
Last Modified By : steeven lee
e-mail : [email protected]
Purpose : Change user password in ldap database
Last modified : 28 Mar 2001
*/
include ("includes/global.inc.php");
session_start();
// ID comparison between logged hash and session. If they are both the same, let the user to go on...
$dbq = $db->execute("select * from tblLoggedUsers where hash = '$ID'");
$log_id = $dbq->fields['log_id'];
$user_id = $dbq->fields['user_id'];
$username = $dbq->fields['username'];
$password = $dbq->fields['password'];
$dbq->close();
if ($log_id == ""){
Header("Location: index.php?error_id=1");
} else {
if ($txtpassword1 != $txtpassword2){
Header("Location: preferences.php?error=密码不匹配");
exit;
}
$con=ldap_connect("localhost");
ldap_bind($con,"cn=Manager, dc=icareu, dc=com","secret");
$mod["userpassword"] = "{crypt}".crypt($txtpassword1);
$dbq = $db->execute("select user_id,username,password from tblLoggedUsers where hash='$ID'");
$username = $dbq->fields['username'];
$dbq->close();
ldap_modify($con,"uid=$username, dc=icareu, dc=com",$mod);
ldap_close($con);
$dbq = $db->execute("update tblLoggedUsers set password='$txtpassword' where hash='$ID'");
$dbq->close();
Header("Location: mailbox.php?mbox_id=INBOX");
}
?>
|