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
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();
}
}