在線增減.htpasswd內的用戶
<?php
include("./class.Htpasswd.php3");
/* 請修改此.htpasswd文件路徑
*/
$htpasswdfile = "/usr2/amitc/.htpasswd";
// 此行請勿修改
echo '<FORM ACTION="'.$PHP_SELF . '" METHOD=POST>';
?>
<Table BORDER><TR>
<TD>Username: </TD>
<TD><INPUT TYPE=text name="username"></TD>
</TR><TR>
<TD>Password: </TD>
<TD><INPUT TYPE=text name="password"></TD>
</TR><TR>
<TD>
<INPUT TYPE=radio NAME=doop VALUE="verify" CHECKED> Verify Password <BR>
<INPUT TYPE=radio NAME=doop VALUE="add" > 加入新用戶<BR>
<INPUT TYPE=radio NAME=doop VALUE="delete" > 刪除用戶 <BR>
<INPUT TYPE=radio NAME=doop VALUE="change" > 更改密碼 <BR>
</TD>
<TD>
<INPUT TYPE=submit name="operation">
</TD></TR>
</TR>
</TABLE>
</FORM>
<?php
if(!isset($operation)) {
}
else {
echo "<FONT COLOR=RED> <HR>";
echo "您剛進行了此項操作,請核查 <BR><HR>";
echo "您要對用戶 $username 及密碼 $password 進行 = [$doop] <BR>";
$handle = new Htpasswd($htpasswdfile);
switch ($doop) {
case 'add':
print "用戶<BR>";
$retval = $handle->addUser($username, $password);
if($retval) {
print "用戶 [$username] 加入成功!<BR>";
} else {
print "加入用戶 [$username] 失敗.<BR>";
}
break;
case 'change':
print '修改密碼<BR>';
$retval = $handle->changePass($username, $password);
if($retval) {
print "[$username] 的密碼修改成功.<BR>";
} else {
print "[$username] 的密碼修改失敗.<BR>";
}
break;
case 'delete':
print '刪除用戶<BR>';
$retval = $handle->deleteUser($username);
if($retval) {
print "[$username] 被刪除.<BR>";
} else {
print "刪除 [$username]時發生錯誤.<BR>";
}
break;
case 'verify':
print 'Code to verify user's password<BR>';
$retval = $handle->verifyUser($username, $password);
if($retval) {
print "[$username] verifies okay with password [$password]<BR>";
} else {
print "Verify Error for [$username] with [$password] (wrong password or user doesn't exist!) <BR>";
}
break;
default:
print '您要中斷? <BR>';
}
echo "</FONT>";
}
?>