Last active
January 5, 2017 05:06
-
-
Save jgornick/51169 to your computer and use it in GitHub Desktop.
PHP: Generate a new htpasswd file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if (sizeof($_POST) > 0) { | |
| $return_code = -1; | |
| // Command to generate a new htpasswd | |
| $command = 'htpasswd -nb ' . $_POST['new_username'] . ' ' . $_POST['new_password']; | |
| // Execute command | |
| exec($command, $result); | |
| // Check to make sure we got output and replace the current htpasswd with the new password | |
| if (!empty($result[0])) | |
| exec('echo ' . $result[0] . ' >| http-access', $array, $return_code); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment