public bool isUserInDB(string login, string password) { using (MD5 md5Hash = MD5.Create()) { string hash = CryptoMD5.GetMd5Hash(md5Hash, password); StringBuilder myString = new StringBuilder(); myString.Append("SELECT id_user FROM orblanc.user where login_user="******"'" + login + "'"); myString.Append(" and password_user="******"'" + hash + "';"); MySqlConnection myconnexion = Global.InitMySqlConnection(Global.DBLogin, Global.DBPassword, Global.DBHost, Global.DBName, Global.Port, false); ResultSelectOneValue result = Global.selectOneValue(myconnexion, myString.ToString()); if (String.IsNullOrEmpty(result.result)) { return(false); } else { return(true); } } }
// return one value from db public static ResultSelectOneValue selectOneValue(MySqlConnection myConnection, string query) { string firstResult = string.Empty; myConnection.Open(); try { MySqlCommand cmd = myConnection.CreateCommand(); cmd.CommandText = query; cmd.CommandTimeout = 600; MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { object oVal = reader.GetValue(0); firstResult = DBNull.Value.Equals(oVal) ? String.Empty : oVal.ToString(); } reader.Close(); ResultSelectOneValue ret = new ResultSelectOneValue(firstResult, false); return(ret); } catch (Exception ex) { Console.WriteLine(ex.Message + " Query:" + query); ResultSelectOneValue ret = new ResultSelectOneValue(ex.Message.ToString(), true); return(ret); } finally { myConnection.Close(); } }
//public int GetDistance(double myLatitude, double myLongitude, double stationLatitude, double stationLongitude) //{ // //GeoCoordinate positionDépart // return 0; //} /// <summary> /// retourne true si login existant /// </summary> /// <param name="login"></param> /// <returns></returns> public bool isLoginInDB(string login) { StringBuilder myString = new StringBuilder(); myString.Append("SELECT id_user FROM orblanc.user where login_user="******"'" + login + "'"); myString.Append(";"); MySqlConnection myconnexion = Global.InitMySqlConnection(Global.DBLogin, Global.DBPassword, Global.DBHost, Global.DBName, Global.Port, false); ResultSelectOneValue result = Global.selectOneValue(myconnexion, myString.ToString()); if (String.IsNullOrEmpty(result.result)) { return(false); } else { return(true); } }