SoFunction
Updated on 2025-04-09

Online increase or decrease users within .htpasswd

Online increase or decrease users within .htpasswd

<?php  
include("./.php3");  

/* Please modify this .htpasswd file path
*/  
$htpasswdfile = "/usr2/amitc/.htpasswd";  


// Please do not modify this line.
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" > Join a new user<BR>
<INPUT TYPE=radio NAME=doop VALUE="delete" > Delete user <BR>
<INPUT TYPE=radio NAME=doop VALUE="change" > Change Password <BR>
</TD>  
<TD>  
<INPUT TYPE=submit name="operation">  
</TD></TR>  
</TR>  
</TABLE>  
</FORM>  
<?php  
if(!isset($operation)) {  
}  
else {  
echo "<FONT COLOR=RED> <HR>";  
echo "You have just performed this operation, please check <BR><HR>";
echo "You want to perform = [$doop] <BR>";
$handle = new Htpasswd($htpasswdfile);  

switch ($doop) {  
case 'add':  
print "User<BR>";
$retval = $handle->addUser($username, $password);  
if($retval) {  
print "User [$username] Joined successfully!<BR>";
} else {  
print "Add user [$username] failed.<BR>";
}  
break;  

case 'change':  
print 'Modify password<BR>';
$retval = $handle->changePass($username, $password);  
if($retval) {  
print "[$username] password modified successfully.<BR>";
} else {  
print "[$username] password modification failed.<BR>";
}  
break;  

case 'delete':  
print 'Delete user<BR>';
$retval = $handle->deleteUser($username);  
if($retval) {  
print "[$username] was deleted.<BR>";
} else {  
print "An error occurred while deleting [$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 'You want to interrupt? <BR>';
}  
echo "</FONT>";  
}  
?>