I am looking to know how I can edit my code in order to encrypt users passwords. At the moment the user fills in an HTML form which submits to customerRegister.php
which goes through a series of validations before submitting the query.
customerRegister.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);
Those details are then passed to userLoginQueries.php where the query is executed.
userLoginQueries.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();
}
When the user enters their login information the following query is ran:
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 can I modify my code so that the users password is encrypted?