public void BaseDeDatosDisponible() { MySqlConnection connection = new MySqlConnection(); connection.ConnectionSource = new AppSettings(); connection.Connect(); Assert.IsTrue(connection.Open(), $"Base de datos no disponible"); }
public void EjecutarNoQuery() { MySqlConnection conexion = new MySqlConnection(); conexion.ConnectionSource = new AppSettings(); conexion.Connect(); MySqlCommand comando = new MySqlCommand("update beer set be_content = 50 where be_id = 1"); Assert.IsTrue(conexion.ExecuteNonQuery(comando)); }
public void EjecutarQuery(string tablaBaseDatos) { MySqlConnection conexion = new MySqlConnection(); conexion.ConnectionSource = new AppSettings(); conexion.Connect(); MySqlCommand comando = new MySqlCommand("select * from " + tablaBaseDatos); DataTable tabla = conexion.ExecuteQuery(comando); Assert.IsTrue(tabla.Rows.Count > 0); }
/// <summary> /// Obtiene la ultima id insertada en la base de datos /// </summary> /// <returns></returns> private int ObtenerUltimaID() { MySqlConnection conexion = new MySqlConnection(); conexion.ConnectionSource = new AppSettings(); conexion.Connect(); MySqlCommand comando = new MySqlCommand("select be_id as ultima_id from beer order by be_id desc limit 1;"); DataTable tabla = conexion.ExecuteQuery(comando); DataRow row = tabla.Rows[0]; int ultimoId = (int)row["ultima_id"]; return(ultimoId); }
// establish database connection private bool SetDatabaseConnection() { conn = new MySqlConnection(); if (conn.Connect()) { Session["conn"] = conn; return(true); } else { return(false); } }
protected void login_Click(object sender, EventArgs e) { if (Page.IsValid) { string username = Username.Text; string password = Password.Text; //Spassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); MySqlConnection conn = new MySqlConnection(); PasswordHasher hasher = new PasswordHasher(); if (conn.Connect()) { if (!conn.ValidateUsername(username)) { Label1.Text = "Invalid username"; } else { string dpass = conn.MatchPassword(username); PasswordVerificationResult result = hasher.VerifyHashedPassword(dpass, password); if (result == PasswordVerificationResult.Failed) { Label1.Text = "Invalid password"; } else { Session["authenticated"] = true; FormsAuthentication.RedirectFromLoginPage(username, CheckBox1.Checked); } } } else { Response.Write("<script>alert(\'Database connection failed\')</script>"); } } }
private string Usernamevalidation(string s) { string username = s; bool validUsername = username.All(c => Char.IsLetterOrDigit(c)); string label = ""; if (username.Length < 8 || username.Length > 12) { label = "Invalid username, must be between 8-12 characters!"; } else if (!validUsername) { label = "Invalid username, must use letters or numbers!"; } else { MySqlConnection conn = new MySqlConnection(); if (conn.Connect()) { if (conn.ValidateUsername(s)) { label = "Username already exists. Please choose another one!"; } else { label = "You can use this username."; } conn.Disconnect(); } else { Response.Write("<script>alert(\'Database connection failed\')</script>"); } } return(label); }
protected void creating_Click(object sender, EventArgs e) { string username = Username.Text; string label = Usernamevalidation(username); int validation = 1; while (true) { if (label == "You can use this username.") { creatingInfo.Text = ""; } else { creatingInfo.Text = label; validation = 0; break; } String password = Password.Text; label = PasswordValidation(password); if (label == "OK") { creatingInfo.Text = label; } else { creatingInfo.Text = label; validation = 0; break; } string rePassword = RePassowrd.Text; if (password != rePassword) { creatingInfo.Text = "Passwords don't match!"; validation = 0; break; } if (validation == 1) { //password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5"); PasswordHasher hasher = new PasswordHasher(); String hashedPassword = hasher.HashPassword(password); MySqlConnection conn = new MySqlConnection(); if (conn.Connect()) { User user = new User(0); user.firstName = FName.Text; user.username = username; user.lastName = LName.Text; user.password = hashedPassword; user.email = Email.Text; conn.InsertUser(user); conn.Disconnect(); Server.Transfer("Login.aspx", true); } else { Response.Write("<script>alert(\'Database connection failed\')</script>"); } } } }