ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[toc] ## 加解密 ``` $pwd = '123456'; $hash = password_hash($pwd, PASSWORD_DEFAULT); if (!password_verify('123', $hash)) { echo '密码错误'; } else { echo '密码正确'; } ``` 自动加盐值且不需要保存盐值 ## 过滤输入 ### html 1. `htmlentities`该函数会将所有HTML标签字符(&、<、>等)转化为对应的HTML实体 2. `html_entity_decode`将所有html实体转换成html 3. `htmlspecialchars`、`htmlspecialchars_decode` 4. `strip_tags`去除所有html标签 ## 验证输入 ### filter_var 可用于验证布尔值、电子邮件地址、浮点数、整数、IP、正则表达式和URL ~~~ <?php $input = 'xxx@163.com'; $isEmail = filter_var($input, FILTER_VALIDATE_EMAIL); if ($isEmail !== FALSE) {     echo 'success'; } else {     echo 'failed'; } ~~~ ### 组件 * [aura/filter](https://packagist.org/packages/aura/filter) * [respect/validation](https://packagist.org/packages/respect/validation) * [symphony/validator](https://packagist.org/packages/symfony/validator)