Login or create account with php

Ashok Chandraa year ago

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();
?>
Anton Tananaeva year ago

We don't allow sharing personal contact information on this forum. Please don't share your email address or any other contact details.

Ashok Chandraa year ago

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

Anton Tananaeva year ago
Ashok Chandraa year ago

Thanks for hashing algorithm now code is working. :)

Jtcruz9 months ago

Ashok Chandra can you share the complete code so we can use it as a model?

Ashok Chandra9 months ago

I have deleted it. Don't go with php, just modify original code