我有一个创建个人资料的注册表单和一个“编辑个人资料”页面,只要用户还输入密码,他们就可以更改信息。
问题是“编辑配置文件”页面只确保密码的前 8 个字符匹配。或者,实际上,我想更好的描述是 crypt() 函数只编码前 8 个字符。
这是我的注册表单代码:
$password = $_REQUEST['password'];
// Checks to make sure that the password isn't blank
if (!$password) {
handle_error("You have left the password field blank.", "Blank Password");
//handle_error() is a custom function
}
这是我将其插入 MySQL 数据库的代码:
$insert_sql = sprintf("INSERT INTO users (first_name, last_name, pen_name, website, password, email, user_bio, user_reason, hash, profile_pic) " .
"VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');",
mysql_real_escape_string($first_name),
mysql_real_escape_string($last_name),
mysql_real_escape_string($pen_name),
mysql_real_escape_string($website),
mysql_real_escape_string(crypt($password, $email)),
mysql_real_escape_string($email),
mysql_real_escape_string($bio),
mysql_real_escape_string($reason),
mysql_real_escape_string($hash),
mysql_real_escape_string($upload_filename));
“hash”变量的用途与密码无关,所以忽略它。
这是“编辑配置文件”代码的代码。
$password_query = "SELECT * FROM users WHERE user_id = " . $user_id;
$password_query_run = mysql_query($password_query);
$password_array = mysql_fetch_array($password_query_run);
$password_old_hash = $password_array['password'];
$password_new_hash = crypt($password, $email);
if(!($password_new_hash === $password_old_hash)) {
handle_error("The Password you entered does match what we have in our system.","Wrong Password.");
}
我对 PHP 比较陌生,但我确实自己编写了所有代码,所以如果有人需要任何澄清,我会很乐意解释自己。
正如我所说,问题在于我的页面只关心密码的前 8 个字符。当我尝试使用错误的密码验证“编辑个人资料”时,会出现错误。如果我将密码留空,则会出现错误。但是,如果我正确输入了前 8 个字符,然后是一堆乱码,它就会接受密码!我不确定是否有一些我没有得到的 crypt() 或字符串的功能。
哦,我正在做 (!($string1 === $string2)),但我已经尝试了 strcomp() 函数,它的工作方式相同。
非常感谢!