gpt4 book ai didi

php - 使用 md5 散列密码

转载 作者:行者123 更新时间:2023-11-29 00:31:04 25 4
gpt4 key购买 nike

我想使用 MD5 对数据库中的注册密码进行散列处理,登录时也是如此,但问题是在注册过程中密码被散列处理,但在登录过程中系统工作,因为这是不正确的密码

注册.php

 //ADD MD5 hash to the password 
$db_pass=md5($pass1);
//************Insert all the user's input to the database**************************//
$query = mysql_query("INSERT INTO user(user_name, first_name, last_name, governorate,
district, village, birth_date, email_address, specialization, password,
registered_date)VALUES('$username', '$firstname', '$lastname', '$governorate',
'$district', '$village', '$bdate', '$email', '$specialization', '$db_pass',
now())") or die("could not insert data");

登录.php

$pass = md5($pass);

$sql=mysql_query( "SELECT user_id, email_address, first_name, user_name FROM user
WHERE email_address='$email'
AND password='$pass'LIMIT 1") or die("error in user table");

最佳答案

您不应该使用 MD5。它不安全,而且速度太快,您无法将其用于密码散列(如果您不明白为什么使用快速密码散列算法不是一个好主意,请查看 Wiki 页面 Brute-force attacks)。你应该考虑使用类似 Bcrypt 的东西.

您可以通过 crypt function 使用 Bcrypt .

$userPassword = 'testpassword';
$hashed = crypt($userPassword, '$2a$15$usesomesillystringforsalt$');
echo $hashed;

正如上面有人提到的,ircmaxell 有一个 pretty good library在github上可用。该库与 password_hash 函数向前兼容,它将在 PHP 5.5(目前处于 BETA 阶段)中可用。

关于php - 使用 md5 散列密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16495667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com