这是我的代码,但当涉及到使用 Bcrypt 对密码进行哈希处理时,我感到很困惑:
<?php
session_start();
include_once('bcrypt.php');
$db_host = 'localhost';
$db_user = '';
$db_pass = '';
$db_name = 'credentials';
if (!isset($_POST['userName']))
{
echo 'You did not enter a valid username.';
exit;
}
if (!isset($_POST['pass']))
{
echo 'You did not enter a valid password.';
exit;
}
$con = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($con->connect_error)
{
die('Connect Error (' . $con->connect_errno . ') ' . $con->connect_error);
}
$sql = "SELECT userName, pass FROM `Members` WHERE userName = ?";
if (!$result = $con->prepare($sql))
{
die('Query failed: (' . $con->errno . ') ' . $con->error);
}
if (!$result->bind_param('s', $_POST['userName']))
{
die('Binding parameters failed: (' . $result->errno . ') ' . $result->error);
}
if (!$result->execute())
{
die('Execute failed: (' . $result->errno . ') ' . $result->error);
}
$result->store_result();
if ($result->num_rows == 0)
{
die('There is no such username in our database.');
}
$result->bind_result($db_username, $db_password);
$result->fetch();
$result->close();
$con->close();
$bcrypt = new Bcrypt(15);
if ($bcrypt->verify($pass, $db_password))
{
$_SESSION['userName'] = $db_username;
header('location:index.html');
exit;
}
else
{
echo 'Incorrect username or password.';
}
这是我点击提交按钮登录后遇到的错误:
Warning: include_once(bcrypt.php): failed to open stream: No such file or
directory in C:\Users\Julian Buscema\Desktop\Subpost.me\htdocs\connectivity-
login.php on line 3
Warning: include_once(): Failed opening 'bcrypt.php' for inclusion
(include_path='.;C:\Users\Julian Buscema\Desktop\Subpost.me\php\PEAR') in
C:\Users\Julian Buscema\Desktop\Subpost.me\htdocs\connectivity-login.php on line 3
You did not enter a valid username.
我相信我缺少 bcrypt.php,但我从未使用过 Bcrypt,所以我不太确定从这里该去哪里。
最佳答案
问题出在您的包含文件上,您的根目录中缺少bcrypt.php
,您不需要像这样使用Bcrypt
,因为Bcrypt
已在 php 中实现,您可以使用函数代替。
关于php - 困惑实现 Bcrypt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26498270/