• 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 /
  • Help Room /
avatar image
Question by kiroga17 · Sep 12, 2016 at 05:48 PM · unity 5databaseloginscene loadmd5

Different md5 hash

I'm doing a login window in unity 3d. first I have a textbox to input a user and a password, the password is converted to md5, then is checked in a db, if user and md5 match the entries it returns true, then I load another scene. after a while if a connection fail, it loads again the Login scene but when I input the correct user and password it generates a different hash, what could be the problem, I'm gonna attach my script, any help is appreciated, thanks in advance.

Blockquote

IEnumerator MyAsyncVerifyUserData(string User, string Password) { DataTable Login = new DataTable(); OdbcDataAdapter ladpt_adapter = new OdbcDataAdapter(); var HashString = FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Trim(),"MD5"); print (HashString); OdbcDBCom = OdbcDBConnx.CreateCommand(); OdbcDBCom.CommandText = "Execute spFindUserData '"+User+"','"+HashString+"'"; ladpt_adapter.SelectCommand = OdbcDBCom; ladpt_adapter.Fill(Login);

     if (Login!=null)
     {
         print ("si != null");
         //                    print (Login.TableName.ToString());
         print (Login.Columns[0].ColumnName);
         //                    Credentials = false;
         if(Login.Columns[0].ColumnName=="intUserId")
         {
             if(Login.Rows.Count>0)
             {
                 print ("datos Correctos");                            
                 yield return Ninja.JumpToUnity;
                 Application.LoadLevel("Next Scene");

                 yield return Ninja.JumpBack;
             }
             else{
                 print ("datos Incorrectos");
             }
         }
         
         
     }
     LoadingEffectC.loading = false;
     yield return null;
 }


Blockquote

Comment

People who like this

0 Show 0
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

· Add your reply
  • Sort: 
avatar image

Answer by kiroga17 · Sep 12, 2016 at 05:59 PM

This is my full code

public class Access3 : MonoBehaviour {

 [Header("GUI")]
 public GUIStyle Background;
 public GUISkin Skin;
 public GUIStyle YardPlaning3D;
 [Space(10)]
 [Header("CONEXION BASE DE DATOS")]
 public bool Real = false;
 Rect windowRect;
 public float differenceW = 1;
 string user="";
 string passwordToEdit = string.Empty;
 char passwordToEdit2;
 bool activate = true;
 string SP = "";
 bool once = true;
 bool MandarQuery = false;
 bool threadTrue = true;

// bool Actualizando = false; CreateODBC CScreateODBC; Task task; Task taskConnection;

 //Methodo conexion
 public static OdbcCommand    OdbcDBCom = new OdbcCommand();
 public static OdbcConnection OdbcDBConnx = new OdbcConnection();
 public static OdbcDataReader reader;// = new OdbcDataReader();

// OdbcDataAdapter ladpt_adapter = new OdbcDataAdapter();

 bool Conection=true;
 bool Credentials=true;
 bool ConectAndCred = false;

// bool ConnectionFail = false; // string ErrorConexion="";

// string Password="";

 void Awake(){
     Screen.SetResolution(Screen.width,Screen.height,false);
     passwordToEdit=string.Empty;
     this.StartCoroutineAsync(MyAsyncConnection(),out taskConnection);

 }

 IEnumerator MyAsyncConnection(){
         OdbcDBConnx = new OdbcConnection();
         if (Real){
             OdbcDBConnx.ConnectionString = "Driver={Sybase ASE ODBC Driver};NetworkAddress=xxx.xxxx.xxx.xx;"+
                 "Db=xxxxxx;Uid=xxx;Pwd=;xxxx";}
         else{

OdbcDBConnx.ConnectionString = "Driver={Sybase ASE ODBC Driver};NetworkAddress=xxx.xxxx.xxx.xx;"+ "Db=xxxxxx;Uid=xxx;Pwd=;xxxx";}

         OdbcDBConnx.Open();
         Conection = true;
     yield return null;
 }

 IEnumerator MyAsyncVerifyUserData(string User, string Password){
     DataTable Login = new DataTable();
     OdbcDataAdapter ladpt_adapter = new OdbcDataAdapter();
     var HashString = FormsAuthentication.HashPasswordForStoringInConfigFile(Password.Trim(),"MD5");
     print (HashString);
     OdbcDBCom = OdbcDBConnx.CreateCommand();
     OdbcDBCom.CommandText = "Execute spFindUserData '"+User+"','"+HashString+"'";
     ladpt_adapter.SelectCommand = OdbcDBCom;
     ladpt_adapter.Fill(Login);


     if (Login!=null)
     {
         print ("si != null");
         //                    print (Login.TableName.ToString());
         print (Login.Columns[0].ColumnName);
         //                    Credentials = false;
         if(Login.Columns[0].ColumnName=="intUserId")
         {
             if(Login.Rows.Count>0)
             {
                 print ("datos Correctos");                            
                 yield return Ninja.JumpToUnity;
                 Application.LoadLevel("Next Scene");

                 yield return Ninja.JumpBack;
             }
             else{
                 print ("datos Incorrectos");
             }
         }
         
         
     }
     LoadingEffectC.loading = false;
     yield return null;
 }


 void FixedUpdate() {
 
     differenceW = (Screen.width/12.8f) / 100f;
 }

 public  string Md5Sum(string strToEncrypt)
 {
     System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding();
     byte[] bytes = ue.GetBytes(strToEncrypt);
     
     // encrypt bytes
     System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
     byte[] hashBytes = md5.ComputeHash(bytes);
     
     // Convert the encrypted bytes back to a string (base 16)
     string hashString = "";
     
     for (int i = 0; i < hashBytes.Length; i++)
     {
         hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
     }
     
     return hashString.PadLeft(32, '0');
 }


 void OnGUI() {

     if (activate)
     {
         GUI.FocusControl("USER");
         activate=!activate;
     }

     GUI.Box( new Rect (0,0,Screen.width,Screen.height),"",Background);
     GUI.skin = Skin;
     windowRect = new Rect(225*differenceW,200*differenceW,800*differenceW,300*differenceW); 
     windowRect = GUI.Window( 0, windowRect, DoMyWindow, "Log In");
     GUI.Box(new Rect(50*differenceW,50*differenceW,600*differenceW,75*differenceW),"Yard Planning 3D",YardPlaning3D);
     GUI.FocusWindow(0);

 }



 void DoMyWindow(int windowID) {
     GUILayout.BeginArea(new Rect(100*differenceW,100*differenceW,800*differenceW,300*differenceW));
     GUILayout.BeginHorizontal();
     GUILayout.Label("Usuario",GUILayout.Width(100f*differenceW));
     GUILayout.Space((40f*differenceW));
     GUI.SetNextControlName("USER");
     user = GUILayout.TextField(user,GUILayout.Width(300f*differenceW));
     GUILayout.EndHorizontal();
     
     GUILayout.BeginVertical();
     GUILayout.Space((30f*differenceW));
     GUILayout.EndVertical();
     GUILayout.BeginHorizontal();
     if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return)
     {
         if ((passwordToEdit != "") && (user != "") && (LoadingEffectC.loading==false))
         {
             LoadingEffectC.loading = true;
             this.StartCoroutineAsync(MyAsyncVerifyUserData(user,passwordToEdit),out task);
             print(task.State);
         }
         
     }
     GUILayout.Label("Password",GUILayout.Width(120f*differenceW));
     GUILayout.Space((20f*differenceW));
     passwordToEdit = GUILayout.PasswordField(passwordToEdit.Trim(),"*"[0],GUILayout.Width(300f*differenceW));
     if ((passwordToEdit != "") && (user != "") && (LoadingEffectC.loading==false))
     {
         GUILayout.Space((40*FixRes.x));
         GUI.SetNextControlName("Log In");
         if (GUILayout.Button(new GUIContent("Log In")))
         {
             if ((passwordToEdit != null) && (user != null))
             {
                 LoadingEffectC.loading = true;
                 this.StartCoroutineAsync(MyAsyncVerifyUserData(user,passwordToEdit),out task);
                 print(task.State);
             }
         }
     }
     
     

         GUILayout.EndHorizontal();
         GUILayout.BeginHorizontal();
         GUILayout.Space((220*FixRes.x));
         
         if (!Conection)
         {     
             GUILayout.Label("Error de Conexion",GUILayout.Width(300f*differenceW));
             LoadingEffectC.loading = false;
         }
         if (!Credentials)
         {
             GUILayout.Label("Credenciales incorrectas",GUILayout.Width(300f*differenceW));
             LoadingEffectC.loading = false; 
         }
         GUILayout.EndHorizontal();
     GUILayout.EndArea();
 }

}

Comment

People who like this

0 Show 0 · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

108 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error at database connection : SocketException: An address incompatible with the requested protocol was used. How do I solve it? 1 Answer

Problem with Google play services 2 Answers

Using Facebook Login unity Pc Build 0 Answers

Vivox Language Choose 0 Answers

i need help unity get data from php 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