为了账号安全,请及时绑定邮箱和手机立即绑定

加密登录密码

加密登录密码

PHP
繁星点点滴滴 2021-12-24 09:07:11
有人可以看到我的代码有什么问题吗?当我尝试登录时,它无法识别密码。我有非常相似的 admin 代码,它正在工作,但这个不是。function register_client(){  if(isset($_POST['register'])){    $client_name     = escape_string($_POST['client_name']);    $client_surname  = escape_string($_POST['client_surname']);    $client_email    = escape_string($_POST['client_email']);    $client_phone    = escape_string($_POST['client_phone']);    $client_password = escape_string($_POST['client_password']);    $country         = escape_string($_POST['country']);    $city            = escape_string($_POST['city']);    $zip_code        = escape_string($_POST['zip_code']);    $client_address  = escape_string($_POST['client_address']);    $client_password = password_hash($password, PASSWORD_BCRYPT, array('cost' =>10));    $get_query = query("SELECT client_email FROM client_db");    confirm($get_query);    $tem = 0;    while($row = fetch_array($get_query)){    $check_mail = $row['client_email'];      if($client_email === $check_mail){        $tem++;      }    }    if($tem === 0){      $query = query("INSERT INTO client_db(client_name, client_surname, client_email, client_password, client_phone, country, city, zip_code, client_address) VALUES('{$client_name}', '{$client_surname}', '{$client_email}', '{$client_password}',  '{$client_phone}', '{$country}', '{$city}', '{$zip_code}', '{$client_address}') ");      confirm($query);      redirect("client_login.php");    }else{      set_message("incorrect email address");    }  }}function login_client(){  if(isset($_POST['submit_client'])){    $user_email = escape_string($_POST['client_email']);    $password = escape_string($_POST['client_password']);    $query = query("SELECT * FROM client_db WHERE client_email = '{$user_email}' ");    confirm($query);    while($row = fetch_array($query)){    $db_password = $row['client_password'];    $client_id = $row['client_id'];}      if(password_verify($password, $db_password)){      $_SESSION['user_login'] = $client_id;      redirect("index.php?id={$client_id}");    }
查看完整描述

1 回答

?
LEATH

TA贡献1936条经验 获得超6个赞

也许这一行是错误的,因为 $password 在这里是未知的:

$client_password = password_hash($password, PASSWORD_BCRYPT, array('cost' =>10));

应该:

$client_password = password_hash($client_password, PASSWORD_BCRYPT, array('cost' =>10));


查看完整回答
反对 回复 2021-12-24
  • 1 回答
  • 0 关注
  • 145 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信