Skip to content

Instantly share code, notes, and snippets.

@jgornick
Last active January 5, 2017 05:06
Show Gist options
  • Save jgornick/51169 to your computer and use it in GitHub Desktop.
Save jgornick/51169 to your computer and use it in GitHub Desktop.
PHP: Generate a new htpasswd file
<?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