Help connection to SQL via Json file

Hello, i’ve recently been working on an app to the company i work on, in it i’ll need a login system and also insert information on an SQL database, all via Json files.

I’m programming verything on C#.

I allready have a script to write/Read Jsonfiles for the login, however, i have no idea on how to use it for connecting with SQL (don’t know even how to connect unity with sql by the simple method yet!)

I need help on making my login system then.

here’s the script i have for Login

using LitJson;
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

public class Login_JSon : MonoBehaviour
{


    public LogSenha Player = new LogSenha("0", "0", 0);
    JsonData playerjson;

    public string Login = "abc"; //para teste
    public string Pass = "def";  //para teste
    public string Usuario;
    public string Senha;


    [SerializeField]
    public InputField UsuarioField = null;
    [SerializeField]
    public InputField SenhaField = null;
    [SerializeField]
    public Text Feedbackmsg = null;
    [SerializeField]
    public Toggle LembrarDados = null;




    // Use this for initialization
    void Start()
    {

        if (PlayerPrefs.HasKey("remember") && PlayerPrefs.GetInt("remember") == 1)
        {
            UsuarioField.text = PlayerPrefs.GetString("rememberLogin");
            SenhaField.text = PlayerPrefs.GetString("rememberSenha");
        }

    }

    public void FazerLogin()
    {
        Usuario = UsuarioField.text;
        Senha = SenhaField.text;
        int acesso = 0;

        Player = new LogSenha(Usuario, Senha, acesso);
        playerjson = JsonMapper.ToJson(Player);
        File.WriteAllText(Application.persistentDataPath + "/LOGJSON.json", playerjson.ToString());
        acesso++;


        if (LembrarDados.isOn)
        {
            PlayerPrefs.SetInt("remember", 1);
            PlayerPrefs.SetString("rememberLogin", Usuario);
            PlayerPrefs.SetString("rememberSenha", Senha);
        }

        if (Usuario == Login && Senha == Pass)
        {
            Feedbackmsg.CrossFadeAlpha(100f, 0f, false);
            Feedbackmsg.color = Color.green;
            Feedbackmsg.text = "Login Efetuado com Sucesso";
            StartCoroutine(CarregaCena());
        }

        else if (Usuario == "" && Senha == "")
        {
            Feedbackmsg.CrossFadeAlpha(100f, 0f, false);
            Feedbackmsg.color = Color.red;
            Feedbackmsg.text = "Preencha os campos";
            Feedbackmsg.CrossFadeAlpha(0f, 2f, false);
        }

        else if (Usuario == "")
        {
            Feedbackmsg.CrossFadeAlpha(100f, 0f, false);
            Feedbackmsg.color = Color.red;
            Feedbackmsg.text = "Usuario não digitado";
            Feedbackmsg.CrossFadeAlpha(0f, 2f, false);
        }

        else if (Senha == "")
        {
            Feedbackmsg.CrossFadeAlpha(100f, 0f, false);
            Feedbackmsg.color = Color.red;
            Feedbackmsg.text = "Senha não digitada";
            Feedbackmsg.CrossFadeAlpha(0f, 2f, false);
        }

        else
        {
            Feedbackmsg.CrossFadeAlpha(100f, 0f, false);
            Feedbackmsg.color = Color.red;
            Feedbackmsg.text = "Login ou Senha Incorretos";
            Feedbackmsg.CrossFadeAlpha(0f, 2f, false);
            UsuarioField.text = "";
            SenhaField.text = "";
        }
    }

    IEnumerator CarregaCena()
    {
        yield return new WaitForSeconds(0);
        Application.LoadLevel("1Home");
    }


}

public class LogSenha
{
    public string user_Json;
    public string senha_Json;
    public int acesso_num_Json;

    public LogSenha(string user_Json, string senha_Json, int acesso_num_Json)
    {
        this.user_Json = user_Json;
        this.senha_Json = senha_Json;
        this.acesso_num_Json = acesso_num_Json;
    }
}

As ou can see, no sql there yet, just a simple login system.

The way you login and communicate depends heavily on the database system you are using.

Is it a database that’s hosted online? If so then you’ll either want to use an API provided to login, or write your own simple API to do it for you.

If this is more of an internal application and you want to communicate with a local SQL database, then again I would recommend setting up some kind of middle layer to act as a communicator between the Unity produced game / app and the SQL database.

If you’ve not done much with databases before then I very, very strongly recommend you read up on security and some common exploits. For example, you want to make sure you don’t store any admin / master password details within any application you write and you want to avoid transmitting those in any way. Checking out how to avoid SQL injection attacks etc is also very important or you might find out you have all kinds of problems.

Unfortunately, this kind of stuff isn’t easy if you’re new to programming. The code required to do the individual steps is quite straight forward (i.e. writing an API which takes some parameters and returns results isn’t too hard), but actually implementing them all into a cohesive and secure system takes a bit of time and practice.

If you’re able, I would really recommend looking at something like Parse as your database solution. So much of the functionality you need is already written for you and you also have the benefit of having the database managed for you. If you don’t like Parse, there are plenty of other similar systems available.

If you can’t use something like Parse, then start by looking at writing a script to do simple queries. You might be able to do this in Unity but as I said, I’d write it separately to the Unity app and have it run on a server somewhere (what language you use and how you write it depends on the database technology). Your unity app should then communicate with this script (perhaps via a WWW web call) to actually send data to, and retrieve data from the database.

I hope that provides a bit of guidance!