Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Dec 09, 2015 at 10:21 AM by laharl219 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by laharl219 · Dec 07, 2015 at 11:23 AM · c#jsonloginsqlpassword

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by phil_me_up · Dec 08, 2015 at 11:53 AM

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!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image laharl219 · Dec 09, 2015 at 10:21 AM 0
Share

Wow, Thanks for help, i'll connect it with a database stored on a PC (SQL Server management studio). i'll look for all the stuff ou reccomended. Thanks again!

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do you make a password script in c#? 0 Answers

Multiple Cars not working 1 Answer

Checking a hash with random salt 2 Answers

Distribute terrain in zones 3 Answers

How can i create a network mutliplayer login? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges