static bool CheckUserNameSql(string username) { bool haveUsername = false; MySql mySql = new MySql(); MySqlConnection connection = mySql.ConnectSql(); if (mySql.FindUserName(connection, username) == true) { haveUsername = true; } connection.Close(); return(haveUsername); }
static bool CheckPasswordSql(string username, string password) { bool havePassword = false; MySql mySql = new MySql(); MySqlConnection connection = mySql.ConnectSql(); if (mySql.FindPassword(connection, username, password) == true) { havePassword = true; } connection.Close(); return(havePassword); }
static string ReceiveUserData(Socket client) { string username, password, userChoice, userDataString; char sp = ':'; byte[] userData = new byte[512]; string[] spstring = new string[3]; try { int receiveSize = client.Receive(userData); userDataString = Encoding.Default.GetString(userData).Substring(0, receiveSize); Console.WriteLine(userDataString); spstring = userDataString.Split(sp); } catch (Exception err) { Console.WriteLine("Error Message : " + err.Message); } if (spstring[0] == "SingUp") { userChoice = spstring[0]; username = spstring[1]; password = spstring[2]; if (CheckUserNameSql(username) == true) { String HelloTextBuf = "Username is Already in Use"; client.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length))); username = "******"; } else { String HelloTextBuf = "Injoy Server"; client.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length))); Console.WriteLine("Client In"); MySql mySql = new MySql(); MySqlConnection connection = mySql.ConnectSql(); mySql.InsertData(connection, username, password); connection.Close(); } } else if (spstring[0] == "SingIn") { userChoice = spstring[0]; username = spstring[1]; password = spstring[2]; if (CheckPasswordSql(username, password) == false) { String HelloTextBuf = "Username or Password Wrong Input"; client.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length))); username = "******"; } else { String HelloTextBuf = "Injoy Server"; client.Send(Encoding.Default.GetBytes(HelloTextBuf.Substring(0, HelloTextBuf.Length))); Console.WriteLine("Client In"); } } else { Console.WriteLine("WhatSing? I don't know... May be UserOut"); username = "******"; } return(username); }