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.