清理PHP密码字符串

Jon*_*nek 3 php security validation

我有一个PHP页面,允许人们运行htpasswd来更新他们的密码.什么是消毒他们的输入的最佳方法.我不想限制输入,因为我想允许安全密码.这就是我所拥有的.怎么改进?

$newPasswd = preg_replace('/[^a-z0-9~!()_+=[]{}<>.\\\/?:@#$%^&*]/is', '', $inputPasswd);
$cmdline = $htpasswd . " " . $passwd_file . " " . escapeshellarg($username) . " " .escapeshellarg($newpasswd);
exec( $cmdline, $output, $return_var );
Run Code Online (Sandbox Code Playgroud)

Mif*_*Fox 8

ecscapeshellarg功能内置到PHP,并跨越不同的基于壳系统消毒文本,以便没有"不安全"的字符可以传递到EXEC.

http://us2.php.net/manual/en/function.escapeshellarg.php