【发布时间】:2011-09-22 15:15:08
【问题描述】:
我有两个问题。 问题一: 我正在尝试创建一个注册表单,用户可以在其中注册我的网站。 当我运行这个 mysql 语句时,一个 get duplicate entry found 错误:
$sql "insert into users(username, password) values('$username, sha('$password'))";
密钥“密码”的重复条目“da39a3ee5e6b4b0d3255bfef95601890afd80709” 尽管我多次更改了字符串 sha('$password') 。 请帮忙。
else{
include("databaseconnection.php");
$databaseconnect = connect($host,$user,$password,$database)
or die("couldnot connect to database serever.\n");
$database_select = mysql_select_db($database,$databaseconnect)
or die("could not select dabases.\n " .mysql_error());
$query2 = "insert into company(username,password)
values('$username',sha1('$password'))";
$result2 = mysql_query($query2,$databaseconnect);
echo "you have been registered as '$companyloginName' <br/>";
header("Location:/index.php");
我的登录php脚本如下:
$result ="select username, password form users where username ='$username' and password = sha('$password');
if(mysql_num_rows($reuslt)==1){
echo"welcome '$username";
}
【问题讨论】:
-
为什么对密码字段有唯一约束?多个用户不能有相同的密码吗?
-
谢谢你的提问......我实际上删除了密码字段上的唯一约束,但发生的是不同密码的用户可以登录彼此的帐户,因为 sha('$password')和 sha('$password1') 具有相同的 'da39a3ee5e6b4b0d3255bfef95601890afd80709'。
-
补充@Emil所说的,确保允许人们使用相同的密码,或者至少不要显示消息以防他们输入已经存在的密码,因为它会提供很好的安全性应用中的漏洞
-
1.
$databaseconnect被注释掉。 2. 您的$sql变量中缺少=和结束引号。 -
为了安全起见,请不要这样散列您的密码! Read this answer on how to securely hash passwords