- Home /
Unity is not sending password to my PHP. but registers account Hash 0, Salt, 0 ? ?
Hey everyone! OK so it mostly works, it registers an account in my database, however $password is empty, so it encrypts nothing. no idea why it's not sending the password in the field. the Salt and Hash outputs as 0 and 0. but for some reason $password is empty so its encrypting nothing.
this is what I get after it registers. yes it dose register and create an account but... ID: 12 username: test hash: 0 salt: 0
hash and salt should not be 0.
yes everything is set up correctly. :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using TMPro;
public class Registration : MonoBehaviour {
public Text nameField;
public Text passwordField;
public string username;
public string password;
public GameObject CanvusLogginRegister;
public void CallRegister() {
username = nameField.text.ToString();
password = passwordField.text.ToString();
StartCoroutine(Register());
}
IEnumerator Register() {
WWWForm form = new WWWForm();
form.AddField("name", username);
form.AddField("pass", password);
Debug.Log("" + form);
UnityWebRequest www = UnityWebRequest.Post("https://mysitehere.com", form);
yield return www;
if (www.isNetworkError || www.isHttpError)
{
Debug.Log("User creation failed. Error #");
}
else
{
CanvusLogginRegister.SetActive(false);
Debug.Log("User created successfully");
Application.LoadLevel("LoggedIn");
}
}
public void VerifyInputs()
{
// submitButtion.interactable = (nameField.text.Length >= 8 && passwordField.text.Length >= 8);
}
}
Answer by Bunny83 · May 12 at 03:16 AM
First of all get rid of your query string and look up how to use prepared statements. Both of your queries are vulnerable to sql injection.
About your actual issue, it's not really clear from your description what is happening. Your php script also is quite inconsistent with the use of "exit" and "die". USing the construct or die
has many issues as it does not properly handle all possible errors. If the actual command causes an error, the script would just crash. Also die / exit does not cause an error, it just exits the script immediately but adds some additional string to the output before exiting when using a string argument. So you can not detect those exit methods as an error on the Unity side unless you would interpret the returned string. So this would neither result in a network error or an HTTP error.
we can't really help you with debugging on the php side. There are countless possible things that could cause issues. Maybe the generation of the super global $_POST
is disabled on your server? You should echo some debug strings and actually read those on the Unity side in order to know what happens on the PHP side. Also checking the error log on the server may also help.
You may temporarily add those lines at the top of your script:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
This should make php actually return error texts. In production those should be disabled as they are a general security issue. However for debugging this is quite useful.
hey thanks buddy (thanks buddy I'll do that) just wasn't sure why I was getting 0, 0 :) I'll go look into that following a tutorial I saw on YouTube to try and get something simple set up :)