gpt4 book ai didi

c# - 使用 PhpMyAdmin 验证登录

转载 作者:行者123 更新时间:2023-11-29 00:33:35 25 4
gpt4 key购买 nike

我有一个这样的示例表单:

image

我用 select 方法创建了 dbconnect 类,它是这样的:

public List<string>[] Select(string username, string password)
{
string query = "SELECT * FROM ms_user where username = '" + username +
"' and password = '" + password + "'";

//Create a list to store the result
List<string>[] list = new List<string>[2];
list[0] = new List<string>();
list[1] = new List<string>();

//Open connection
if (this.OpenConnection() == true)
{
//Create Command
MySqlCommand cmd = new MySqlCommand(query, connection);
//Create a data reader and Execute the command
MySqlDataReader dataReader = cmd.ExecuteReader();

//Read the data and store them in the list
while (dataReader.Read())
{
list[0].Add(dataReader["username"] + "");
list[1].Add(dataReader["password"] + "");
}

//close Data Reader
dataReader.Close();

//close Connection
this.CloseConnection();

//return list to be displayed
return list;
}
else
{
return list;
}
}

如何使用此方法登录?由于该方法返回一个列表而不是 truefalse 来检查数据库中是否存在该值。

最佳答案

Boolean loginSuccessful = Select(username, password).Count > 0;

但请查看有关如何在数据库中存储密码(例如 this one )和 SQL 注入(inject)(例如 this one )的资源。

关于c# - 使用 PhpMyAdmin 验证登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15404198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com