I am trying to login with php
Can one check my script I am using correct encryption method or not
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "traccar";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
function encryptPassword($password2) {
return hash('sha256', $password2);
}
$email = "[removed]";
$enteredPassword = "[removed]";
$hasedpassword = encryptPassword($enteredPassword);
$sql = "SELECT * FROM tc_users WHERE email = '$email' AND hashedpassword = '$hasedpassword'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "Login successful.";
} else {
echo "Invalid email or password.";
}
$conn->close();
?>
We don't allow sharing personal contact information on this forum. Please don't share your email address or any other contact details.
Yes I know, this is only dummy mail doesn't not exist
Can you tell me I am using write method for reading password or not
Thanks for hashing algorithm now code is working. :)
Ashok Chandra can you share the complete code so we can use it as a model?
I have deleted it. Don't go with php, just modify original code
I am trying to login with php
Can one check my script I am using correct encryption method or not
<?php $servername = "localhost"; $username = "root"; $password = "root"; $dbname = "traccar"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Function to encrypt password using SHA-256 function encryptPassword($password2) { return hash('sha256', $password2); } // Assuming the user is trying to log in with the following credentials $email = "[removed]"; $enteredPassword = "[removed]"; // Replace this with the actual password entered by the user // Encrypt the entered password for comparison with the stored hash $hasedpassword = encryptPassword($enteredPassword); // SQL query to check if the email and password match $sql = "SELECT * FROM tc_users WHERE email = '$email' AND hashedpassword = '$hasedpassword'"; $result = $conn->query($sql); if ($result->num_rows > 0) { // Login successful echo "Login successful."; } else { // Login failed echo "Invalid email or password."; } $conn->close(); ?>