如何在Windows窗体应用程序中验证用户名密码? [英] how to validate username password in windows form application?
本文介绍了如何在Windows窗体应用程序中验证用户名密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void button1_Click_1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"data source=ABHINAV-PC\ABHI;integrated security=true;initial catalog=ATM;");
con.Open();
DataSet ds = new DataSet();
if (textBox1.Text == "@UserName" && textBox2.Text == "@Password")
{
Administrator_Home ah = new Administrator_Home();
ah.Show();
}
else
MessageBox.Show("invalid username or password");
}
推荐答案
Hai
试试这个
Hai
Try this
private void btnOk_Click(object sender, EventArgs e)
{
SqlConnection connect = new SqlConnection(@"data source=ABHINAV-PC\ABHI;integrated security=true;initial catalog=ATM;");
DataTable dt1 = new DataTable();
string strcmd1 = "";
SqlDataAdapter cmd1 = new SqlbDataAdapter;
connect.Open();
strcmd1 = ("SELECT UserName, PassWord FROM Admin WHERE UserName='" & Textbox1.Text.Trim() & "' and Password='" & Textbox1.Text.Trim() & "'");
cmd1 = new SqlDataAdapter(new SqlCommand(strcmd1));
cmd1.SelectCommand.Connection = connect;
cmd1.Fill(dt1)
if ((dt1.Rows.Count > 0)) {
Administrator_Home ah = new Administrator_Home();
ah.Show();
} else {
MessageBox.Show("invalid username or password");
}
}
}
}
CP上有很多例子< a href =http://www.codeproject.com/search.aspx?q=custom+authorization&doctypeid=1%3b2%3b3%3b13%3b5>知识库 [ ^ ]和通过 Google [ ^ ]
There are tons of examples on CP Knowledge Base[^] and via Google[^]
其非常简单的朋友只需使用sql qry,如select * from tbl where username =''和pwd =''
如果你返回结果然后用户可用其他用户可用
its very simple friend just use the sql qry like select * from tbl where username ='' and pwd =''
if u return result then user is available else user s nt available
这篇关于如何在Windows窗体应用程序中验证用户名密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文