如何在csharp c#中使用小写字母控制登录表单 [英] how to control a login form with lowercase in csharp c#
本文介绍了如何在csharp c#中使用小写字母控制登录表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SqlDataAdapter da = new SqlDataAdapter("select * from users where username=''" + txtUser.Text + "''and password=''" + txtPsswrd.Text + "'' ", con);
DataSet ds = new DataSet();
da.Fill(ds, "users");
DataView dv = new DataView(ds.Tables["users"]);
if (dv.Count == 0)
{
MessageBox.Show("wrong username or password");
txtUser.Focus();
txtUser.Text = "";
txtPsswrd.Text = "";
}
else
{
MDI dm = new MDI();
dm.Show();
this.Hide();
}
}
推荐答案
尽管您已经给出了答案,但我想强调的是,您永远不要在SQL查询中使用串联值.这使您容易遇到各种问题,例如:
-SQL注入
-数据类型不匹配等.
因此,不要串联值,而使用 SqlParameter [ ^ ].
因此,您的查询应类似于:
Although you have already given an answer, I want to emphasize that you should never ever use concatenated values inside a SQL query. This leaves you open to different kinds of problems like:
- SQL injection
- data type mismatches and so on.
So instead of concatenating the values, use SqlParameter[^].
So your query should look something like:
SqlDataAdapter da = new SqlDataAdapter("select * from users where username=@username and password=@password", con);
...
区分大小写的搜索查询在这里使用非常简单.
case sensitive search query will very simple to use here..
"select * from users where username COLLATE Latin1_General_CS_AS =''" + txtUser.Text + "''and password COLLATE Latin1_General_CS_AS =''" + txtPsswrd.Text + "'' "
这将执行区分大小写的搜索...并且如果输入的数据大小写与存储的大小写不同,则不会返回任何值...
this will do case sensitive search... and if entered data case is different from that of stored, doesn''t return any value...
在数据库中,如果您存储了用户名和小写的密码,然后最好将所有文本框输入转换为小写.
In your database , if you stored username and password in lowercase, then Better convert all the textbox input to lower.
SqlDataAdapter da = new SqlDataAdapter("select * from users where username='" + txtUser.Text.ToString().ToLower() + "'and password='" + txtPsswrd.TextToString().ToLower() + "' ", con);
或尝试这个
or try this
.lowercase {text-transform: lowercase}
这将使在文本框中输入的数据变为小写.
您必须将cssclass小写分配给文本框.但这不允许您在文本框中添加数字和符号
This will make the data entered in the text box as lowercase.
u have to assign the cssclass lowercase to the textbox. but this wont allow you to add numbers and symbols in textbox
这篇关于如何在csharp c#中使用小写字母控制登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文