The password entered does not match the hashed and salted password in PHP during login

Currently working on a project in Unity where I am trying to implement account creation, login functionality, and saving user data using PHP and MySQL. The registration process is successfully completed, however, I am facing issues with the login process. I have been following the tutorial provided by boardtobits.

During my research, I came across information suggesting that the hash generated during account creation does not match the login hash. This has left me wondering why there is a discrepancy.

Below is the PHP code snippet for the login:

<?php

 $user = 'root';
 $password = 'root';
 $db = 'hostalvillegadata';
 $host = 'localhost';
 $port = 8889;

 $link = mysqli_init();
 $success = mysqli_real_connect(
 $link, 
 $host, 
 $user, 
 $password, 
 $db,
 $port);

// Checking if the connection was successful
if (mysqli_connect_errno()) 
{
echo "1: Connection failed"; 
exit();
}

$username = $_POST["name"];
$password = $_POST["password"];

$namecheckquery = "SELECT username, salt, hash, habitacionesreservadas 
FROM hostalvillegatable WHERE username='" .$username. "';";

$namecheck = mysqli_query($link, $namecheckquery) or die("2: Name check query failed");

if (mysqli_num_rows($namecheck) != 1 ) 
{
 echo "5: No user with name, or more than one";
 exit();
 }

 $existinginfo = mysqli_fetch_assoc($namecheck);
 $salt = $existinginfo["salt"];
 $hash = $existinginfo["hash"];

 $loginhash = crypt($password, $salt);

  if ($hash != $loginhash) 
  {
    echo "6: Incorrect password";
    exit();
   }

    echo "0\t" . $existinginfo["habitacionesreservadas"];

   ?>

And here is the C# code snippet for the login:

public class LogIn : MonoBehaviour
   {
  public InputField nameField;
  public InputField passwordField;

public Button submitButton;

public void CallLogin()
{
    StartCoroutine(Login());
}

IEnumerator Login()
{
    WWWForm form = new WWWForm();
    form.AddField("name", nameField.text);
    form.AddField("password", nameField.text);

    UnityWebRequest www = UnityWebRequest.Post("http://localhost:8080/sqlconnect/login.php", form);
    yield return www.SendWebRequest();

    if (www.downloadHandler.text[0] == '0')
    {
        DataBaseManager.username = nameField.text;
        DataBaseManager.habitacionesreservadas = int.Parse(www.downloadHandler.text.Split('\t')[1]);
    }
    else
    {
        Debug.Log("User login failed. Error #" + www.downloadHandler.text);
    }

}

public void VerifyInputs()
{
    submitButton.interactable = (nameField.text.Length >= 5 && passwordField.text.Length >= 5);
}

C# CODE (DataBaseManager)

public static class DataBaseManager
{
public static string username;
public static int habitacionesreservadas;

public static bool LoggedIn {get { return username != null; } }

public static void LogOut()
{
    username = null;
}

Despite creating multiple accounts with the same password, the system keeps prompting an incorrect password error message. Any suggestions on how to resolve this puzzle?

Looking forward to some insight!

Answer №1

the following code snippet

$existinginfo = msqli_fetch_assoc($namecheck);

needs to be updated to

$existinginfo = mysqli_fetch_assoc($namecheck);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtaining a date and time in PHP from a JavaScript array

I am currently working on implementing a JQuery datetime picker and my goal is to save the selected date and time into a PHP variable for storage in a MySQL database. Despite browsing through various examples, none of them seem to be effective in achieving ...

Can I use newline escapes in a MySQL query?

While browsing through a different stackoverflow question, I came across the following code... $query=" SELECT account.id, client.client_id\n" . " FROM account, client\n" . " WHERE account.id = 19"; I'm wondering if those newline e ...

Utilize jQuery to extract all values from the second cell of a table and store them in an array

I have a task that involves pushing numbers from text boxes into an array. These text boxes are located in the second cell of each table row, while the third cell contains a date picker. Currently, the code snippet provided retrieves all values from both ...

Discovering back-to-back days

I am currently working on a PHP script that utilizes a MySQL database to calculate various climatological parameters based on different variables. While I have successfully completed most of the calculations, there is one particular task that I am struggli ...

My values are failing to transfer to the SQL Server database without generating any error messages. What could be causing this issue

My current project involves using PHP code to post data submitted through a web form to a database table. However, despite my efforts, the data is not getting stored in the database. I have another similar page where the data posting works correctly with t ...

Managing user sessions for a mobile app login in PHP: Best practices

As a professional PHP programmer, my expertise lies in web development and I have limited knowledge about coding for iOS and Android platforms. Currently, I have created RESTful APIs for two mobile apps, one for iOS and the other for Android, which replic ...

What is the cost associated with connecting to a MySQL database in terms of operation expenses?

During certain functions within the code, PHP performs numerous queries on the same tables using loops. Each query currently creates a new database connection, but how costly is this operation? Would reusing the same connection result in a noticeable speed ...

Tips for avoiding the forward slash in a URL parameter

$.ajax({ url: "/api/v1/cases/annotations/" + case_id + "/" + encodeURIComponent(current_plink), When I use encodeURIComponent to escape slashes, it doesn't work as expected. The code converts the "slash" to "%2F", but Apache doesn't reco ...

Tips for identifying duplicate column values within a row prior to updating in MySQL using PHP

New item I am looking to modify row m3 in the table below where the owner is set as 10000. Before making any changes, it's important to verify that this particular row does not contain any duplicate values. For instance, 20 should be flagged and a wa ...

Is it possible to create Excel documents containing statistical graphs and pie charts by utilizing PHP and SQL?

I have a database filled with statistical data that I want to export into an excel file. Can anyone recommend any popular libraries or scripts for generating excel files? Additionally, I am interested in displaying some of the dry numerical data in p ...

PHP script unintentionally wipes out entire WordPress website

Currently, I am dynamically loading data into a WordPress site: This data is being fetched from another website: To accomplish this task, I have inserted the following code snippet into the WordPress page: <div id="this_day_in_history"> < ...

What is the process for sorting non-integer records in MySql?

I need help sorting MySQL records in descending order to retrieve the most recent entry. Here are the records stored as strings: 1/2017 1/2018 2/2017 2/2018 3/2017 I specifically want to retrieve the value 1/2018. The entries correspond to each year an ...

JavaScript code to activate a text box when a checkbox is clicked

I have a dynamic table that is generated by JavaScript based on the selected item from a dropdown list. The table consists of a column for checkboxes, a column for displaying names, and a column for inputting quantities. I would like to have all textboxes ...

Does serving files with PHP result in a noticeable decrease in performance?

Imagine this scenario: example.com/image.jpg is a direct link to the image file. example.com/some-endpoint/image.jpg is a link to a PHP script that retrieves and displays the image after authentication checks. Are there major performance drawbacks to us ...

Wordpress Custom Post Type with a Sleek Slider Plugin

I am currently using a static slick slider to display testimonials on my website. Instead of hardcoding the testimonials, I want to fetch them from a WordPress custom post type that I have created. Can someone guide me in the right direction: <section ...

Sending notifications to all users with OneSignal, rather than just one player

I am facing an issue where I am trying to send a push notification to a single device based on its player_id stored in my database. However, whenever I attempt to do so, the notification ends up being sent to all users instead of just one specific device ...

Get the total number of users and clans in a single MySQLI query

I am trying to retrieve two values from my database. This is the code I have currently for retrieving the values in two separate queries: $con = mysqli_connect("127.0.0.1", $user_database, $password_database, $nama_database) or die("User atau Password Da ...

What is the reason for receiving this £10 with charset=utf8?

When I input a £ symbol into my database, why does it consistently show as £? I initially believed this issue was related to the charset, but I assumed using utf8 would resolve it. UPDATE: I am currently setting the charset like so: $db = new PDO(&a ...

Connecting a Router with CakePHP

Router::connect( 'mylogin', array('controller' => 'User', 'action' => 'xyz', 5) ); Is there a method for transforming the string '/User/xyz/5' stored in a database into an array arr ...

Transferring an Array from PHP to Javascript

I'm attempting to pass a PHP array so that I can use it in JavaScript. The PHP code I have written is shown below: <?php $link = mysqli_connect("localhost", "root", "password", "database"); /* check connection */ if (mysqli_connect_errn ...