duanjing4667 2014-10-21 23:48
浏览 38

困惑的实施Bcrypt

Here's the code I have, but I'm confused when it comes to hashing passwords using 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.';
}

Here is the error I'm getting after I click the submit button to login:

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.

I belive I'm missing bcrypt.php but I've never worked with Bcrypt so I'm not too sure where to go from here.

  • 写回答

1条回答 默认 最新

  • duansang8388 2014-10-22 00:02
    关注

    The problem is with your include file, bcrypt.php is missing from your root directory , you do not need to use Bcrypt like this because Bcrypt is already implemented in php and you can use a function instead.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大