title: Why I am having connection Issues with some kind of passwords in C# using MD5 hash?
body: <p>Depending in what kind of password I use to store in the database my program crashes on "Consulta" method when its trying to do Reader.close() inside the first "if".</p>
  
  <p>For example if I set as password "1234" I have no problems, with "prueba" instead the crash happens and it doesnt even go to "catch".</p>
  
  <p>This is the method to save a new user, which is in a button event.   </p>
  
  <pre><code>private void bbtnGuardar_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
      {
          DB con = new DB(path);
  
          MD5 md5 = MD5.Create();
  
          byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(tbPassword.Text));
          String encryptedPassword = Encoding.Default.GetString(hash);
  
          string query = "INSERT INTO IEM182_LOGIN (USUARIO, PASSWORD) VALUES " +
              "('" + tbUsuario.Text + "', '" + encryptedPassword + "');";
  
          try
          {
              con.Consulta(query);
              MessageBox.Show("Nuevo usuario dado de alta correctamente");
              limpiar_usuario();
          }
          catch
          {
              try
              {
                  con.Cerrar();
                  query = "SELECT * FROM IEM182_LOGIN WHERE USUARIO = '" + tbUsuario.Text + "'";
                  con.Consulta(query);
                  if (con.Reader.Read())
                  {
                      MessageBox.Show("El nombre de usuario ya existe");
                  }
              }
              catch
              {
                  MessageBox.Show("El usuario contiene caracteres no validos");
              }
              con.Cerrar();
      }
  </code></pre>
  
  <p>This is the database class with some methods.</p>
  
  <pre><code>class DB
  {
      private SqlDataReader rdr;
      private string path;
      private SqlConnection con;
      private SqlCommand cmd;
  
      public DB(string cadenaConexion)
      {
          path = cadenaConexion;
          con = new SqlConnection(path);
      }
  
      public void Consulta(string query)
      {
          if (Conexion.State == System.Data.ConnectionState.Open)
          {
              cmd = new SqlCommand(query, con);
              Reader.Close();
              Reader = cmd.ExecuteReader();
          }
          else
          {
              con.Open();
              cmd = new SqlCommand(query, con);
              Reader = cmd.ExecuteReader();
          }
      }
  
      public SqlDataReader Reader
      {
          get { return rdr; }
          set { rdr = value; }
      }
  
      public void Cerrar()
      {
          con.Close();
      }
  
      public SqlConnection Conexion
      {
          get { return con; }
          set { con = value; }
      }
  </code></pre>