c++ CLI - C++ CLI 代码卡住了

c++ cli - C++ Cli code stucked

本文关键字:CLI C++ c++ 代码      更新时间:2023-10-16

我删除了代码中不必要的部分,以阐明代码应该表示什么以及哪些代码实际上应该工作,因为我看到这会混淆引号文本中多余的空间。

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);
}
}
}
};

您提供的代码不适用于任何数字

它唯一做的是

  • 构造一些 SQL 查询
  • 检查其结果

在 SQL 查询构造期间,代码不假定提供任何"数字"。它实际上使用一个名为password_txt->Text的变量,这表明它是某种形式的TextBox控制。代码从中获取"文本"并将其粘贴到查询中,没有任何假设。如果"文本"包含数字,它将粘贴数字。如果"文本"包含"mom_dad-and-MYDOG",代码将完全粘贴该内容。此外,代码已经确保文本将用引号(...' " + Text + " ' ...)括起来,因此SQL语法对数字和文本都有效。

请注意,将

文本粘贴到查询中,无论是否确保引号,都会形成严重的安全问题。如果文本包含引号怎么办?你真的应该在这里使用 QueryParameters。这很严重,但这是一个完全不同的故事。请务必阅读有关它的信息。

回到数字/文本 - 所以,这段代码不关心"数字"。如果您的应用程序不允许密码为"文本",则原因必须位于代码的其他某个块中。

从那password_txt -> Text来看,你可能有一个文本框或类似的东西。检查其events部分。您很可能会找到一些 TextChanged 或 KeyPressed 或 KeyDown 事件处理程序,例如,这些处理程序将过滤掉除数字以外的所有按键。

编辑:另请查看 CrashMstr 建议的内容 - 删除我刚才提到的引号附近的多余空格。 ' 213 '可能会强制使用 213,但' mom '不会与表中的"妈妈"匹配。另一件事 - 确保检查数据库本身中password列的数据类型;)