gpt4 book ai didi

MySQL - 如何加密密码

转载 作者:行者123 更新时间:2023-12-01 00:24:55 24 4
gpt4 key购买 nike

我想知道如何编辑我的代码来加密用户密码。目前,用户填写一个提交给 customerRegister.php 的 HTML 表单,该表单在提交查询之前经过一系列验证。

客户注册.php

registerUser($_POST['firstName'], $_POST['lastName'], $_POST['username'], $_POST['houseNo'], $_POST['StreetName'], $_POST['town'], $_POST['postCode'], $_POST['emailAddress'], $_POST['phoneNumber'], $_POST['password'], $_POST['conPassword'],$_POST['carRegistration'],$_POST['carMake'],$_POST['carModel'],$_POST['carYear'],$_POST['carEngineSize'],$_POST['carFuel']);

function registerUser($firstName, $lastName, $username, $houseNo, $streetName, $town, $postCode, $emailAddress, $phoneNumber, $password, $conPassword, $registration, $carMake, $carModel, $carYear, $carEngineSize, $carFuel) {

$registerQuery = new UserLoginQueries();

/********************************
SERIES OF VALIDATIONS
********************************/

$registerQuery->insertUser($firstName, $lastName, $username, $houseNo, $streetName, $town, $postCode, $emailAddress, $phoneNumber, $password);

然后将这些详细信息传递给执行查询的 userLoginQueries.php。

用户登录查询.php

  public function insertUser($custFirstName, $custLastName, $username, $houseNo, $streetName, $town, $postCode, $email, $number, $pass) {
$sth = $this->conn->prepare("INSERT INTO `customer`(`CustFirstName`, `CustLastName`, `HouseNo`, `StreetName`, `Town`, `PostCode`, `EmailAddress`, `PhoneNumber`, `Username`, `Password`) VALUES (?,?,?,?,?,?,?,?,?,?)");
$sth->bindValue (1, $custFirstName);
$sth->bindValue (2, $custLastName);
$sth->bindValue (3, $houseNo);
$sth->bindValue (4, $streetName);
$sth->bindValue (5, $town);
$sth->bindValue (6, $postCode);
$sth->bindValue (7, $email);
$sth->bindValue (8, $number);
$sth->bindValue (9, $username);
$sth->bindValue (10, $pass);
$sth->execute();
}

当用户输入他们的登录信息时,将运行以下查询:

  public function queryLogin($username, $password) {
$sth = $this->conn->prepare("SELECT * FROM customer WHERE Username = ? AND Password = ? AND UserType = 'Customer'");
$sth->bindValue (1, $username);
$sth->bindValue (2, $password);
$sth->execute();
$count = $sth->rowCount();
return $count;
}

如何修改我的代码以便加密用户密码?

最佳答案

请看一下这个答案:How do you use bcrypt for hashing passwords in PHP? ,你只需要调用 $hash = $bcrypt->hash('password');
注册用户时,然后将密码的散列版本保存到数据库中。然后,您可以使用 $isGood = $bcrypt->verify('password', $hash);

验证用户

关于MySQL - 如何加密密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16154039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com