I have a PHP page that allows people to run htpasswd to update their password. What is the best way to disinfect them. I do not want to severely restrict entry, because I want to allow the use of secure passwords. This is what I have. How can this be improved?
$newPasswd = preg_replace('/[^a-z0-9~!()_+=[]{}<>.\\\/?:@#$%^&*]/is', '', $inputPasswd);
$cmdline = $htpasswd . " " . $passwd_file . " " . escapeshellarg($username) . " " .escapeshellarg($newpasswd);
exec( $cmdline, $output, $return_var );
source
share