else if(updated_password == confirm_password)
{
using (var old_connection = new MySqlConnection("server=localhost;user id=" + old_user + ";database=DB;password=" + old_pass))
{
MySqlCommand old_cmd = new MySqlCommand("ALTER USER'" + old_user + "'@'localhost' IDENTIFIED BY'" + confirm_password + "'", old_connection);
old_cmd.ExecuteNonQuery();
//old_connection.Close();
MessageBox.Show("Password changed successfully.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
//old_connection.Open();
}
}
How do I prevent SQL injection from occurring in the following code? How do I recode it?
I have tried to use the common SQL injection techniques like x' OR 'x'='x in the username and password but the programs immediately returns an error. So those SQL injection only apply when you using the MySQLCommand and NOT the MySQLConnection?