我正在做一个项目,您可以在其中创建一个帐户,使用 php 和 mysql 服务器登录并统一保存用户数据。我完成了所有注册过程并且有效,但我无法登录。我是按照 boardtobits 教程来做的。经过一些研究,我发现创建帐户时生成的哈希值和登录哈希值不同,但为什么呢?PHP 代码 - (用于登录)<?php $user = 'root'; $password = 'root'; $db = 'hostalvillegadata'; $host = 'localhost'; $port = 8889; $link = mysqli_init(); $success = mysqli_real_connect( $link, $host, $user, $password, $db, $port);//check that connection happenedif (mysqli_connect_errno()) {echo "1: Connection failed"; //error code #1 = connection failedexit();}$username = $_POST["name"];$password = $_POST["password"];//check if name exists$namecheckquery = "SELECT username, salt, hash, habitacionesreservadas FROM hostalvillegatable WHERE username='" .$username. "';";$namecheck = mysqli_query($link, $namecheckquery) or die("2: Name check query failed"); // error code #2 - name check query failedif (mysqli_num_rows($namecheck) != 1 ) { echo "5: No user with name, or more than one"; //error code #5 - number of names matching != 1 exit(); } //get login info from query $existinginfo = mysqli_fetch_assoc($namecheck); $salt = $existinginfo["salt"]; $hash = $existinginfo["hash"]; $loginhash = crypt($password, $salt); if ($hash != $loginhash) { echo "6: Incorrect password"; //error code #6 - password does not hash to match table exit(); } echo "0\t" . $existinginfo["habitacionesreservadas"]; ?>
1 回答
PIPIONE
TA贡献1829条经验 获得超9个赞
这条线
$existinginfo = msqli_fetch_assoc($namecheck);
必须是
$existinginfo = mysqli_fetch_assoc($namecheck);
- 1 回答
- 0 关注
- 113 浏览
添加回答
举报
0/150
提交
取消