Online addition and deletion of users in. htpasswd

Source: Internet
Author: User

Online addition and deletion of users in. htpasswd

<? PHP
Include ("./class. htpasswd. php3 ");

/* Modify the path of this. htpasswd file.
*/
$ Htpasswdfile = "/usr2/amitc/. htpasswd ";

// 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"> Add a user <br>
<Input type = radio name = Doop value = "delete"> delete a 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 need to perform = [$ Doop] on the user $ username and password $ password <br> ";
$ Handle = new htpasswd ($ htpasswdfile );

Switch ($ Doop ){
Case 'add ':
Print "User <br> ";
$ Retval = $ handle-> adduser ($ username, $ password );
If ($ retval ){
Print "User [$ username] added successfully! <Br> ";
} Else {
Print "failed to join user [$ username]. <br> ";
}
Break;

Case 'change ':
Print 'change 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] 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 'Do you want to interrupt? <Br> ';
}
Echo "</font> ";
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.