Frage

I took out the unnecessary parts of the code to clarify what the code is supposed to represent and what code should actually work because I see that confuses you extra space in the text in quotation marks.

MySqlDataReader^ myReader;
try
{
  conDataBase -> Open();
  myReader = cmdDataBase -> ExecuteReader();
  //   int count = 0;
  while (myReader -> Read())
  {

    count = count + 1; // This piece of code I want to rewrite,from here to the bottom
                       // of the page,password should not be in the numbers but in the
                       // letters, and that's what I do not know how to do it. 
                       // Statement if should be if (char*) or something like that.
  }  

  if (count == 1)
  {
    MessageBox::Show ("Username and password are correct");
  }
  else if (count > 1)
  {
    MessageBox::Show ("Username and password are duplicates ... access denied!");
  }
  else
  {
    MessageBox::Show ("Username and password are incorrect ... Please enter your username and password!");
  }
}
catch ( Exception^ ex)
{
  MessageBox::Show(ex -> Message);
}
}
}
};
War es hilfreich?

Lösung

The code you provided does not work on any numbers.

The only thing it does is

  • construct some SQL query
  • check its result

During the SQL-query-construction, the code does not assume any "numbers" to be provided. It actually uses a variable called password_txt->Text, which suggests it's some form of TextBox control. The code gets the "Text" from it and pastes it into the query with no assumptions. If the "Text" contained numbers, it would paste numbers. If the "Text" contained "mom_dad-and-MYDOG", the code would paste exactly that. Also, the code already ensures that the text will be wrapped with quotes (...' " + Text + " ' ...), so the SQL syntax will be valid both for numbers and text.

BTW. mind that pasting the text into the query, with quotes ensured or not, forms a serious security issues. What if the text contains a quote? you really should be using QueryParameters here. This is serious, but this is a whole lot different story. Be sure to read about it.

Getting back to numbers/text - So, this code does not care about "numbers". If your application does not allow the password to be "text", then the cause must sit in some other chunk of the code.

Judging from that password_txt -> Text, you've probably got a TextBox or something similar there. Check its events section. It is very probable that you will find some TextChanged or KeyPressed or KeyDown event handler that will, for example, filter-out all key presses except numbers.

// edit: also check out the thing suggested by crashmstr - remove that extra spaces near the quotes I just mentioned. ' 213 ' might be coercible to 213, but ' mom ' will not match "mom" in the table. Another thing - be sure to check what datatype the password column is in the database itself ;)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top