【发布时间】:2015-01-27 09:30:59
【问题描述】:
我正在使用以下代码对 MySQL 数据库中的密码进行加盐和哈希处理:
<?php
function make($string, $salt = '') {
return hash('sha256', $string . $salt);
}
function salt($length) {
return mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
}
$salt = salt(32);
$password = make('password', $salt);
?>
但是,当我尝试将生成的盐插入数据库时,在某些情况下会出现此错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ÜöOòƒ·¡]ŽÖ', 1)' at line 1
我认为这是因为生成了无法识别的字符。有什么办法可以解决这个问题?
【问题讨论】:
-
显示插入的代码
标签: php mysql insert salt sha256