请为我提供有关用户登录权限的帮助 [英] please help me about the user login with its privileges

查看:74
本文介绍了请为我提供有关用户登录权限的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含用户名,密码的表单,我想输入一个条件
如果用户输入了密码和用户名,它会在程序中出现三次错误
该代码有什么问题

I have a form contains the Username, password, and I want to put a condition
that if the user enters the Password and user name, it three times error out of the program
what''s the problem of that code

int count=1;
private void button1_Click(object sender, EventArgs e)
{
Form1 F = new Form1();
SqlConnection con= new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=M_cards;Integrated Security=True;Pooling=False");
con.Open();
SqlCommand cmd1 = new SqlCommand("select username from users",con);
SqlCommand cmd2 = new SqlCommand("select password from users",con);
if (cmd1.ToString() == textBox1.Text & cmd2.ToString() == textBox2.Text)
{
F.Show();
this.Hide();
}
else
{
MessageBox.Show("SORRY,YOUR NAME OR PASWORD ARE WRONG,TRY AGAIN"); 
count++;
if (count >= 3)
{
this.Close(); 
}
}
con.Close(); 
}


请我想知道如何制作系统允许用户进入屏幕
而不是根据授予他的权力(特权)?: confused:
注意:我使用C#和sql server 2005

请回答我的问题并帮助我
请不要迟到回答我的问题
谢谢您的配合.


please i want to know How to Make system allows the user to enter the screen
rather than another, according to the powers (privileges) given to him?:confused:
note : i use C# and sql server 2005

please answer my question and help me
please don''t late to answer my qusetion
thank you for your coopration

推荐答案

每次我执行此代码时,都会显示此消息(对不起,您的名字或密码错误,请再次尝试)数据正确或不正确
谢谢您的配合
Every time i implements this code this message (SORRY,YOUR NAME OR PASWORD ARE WRONG,TRY AGAIN) is shown whether i enter the user data correctly or incorrectly
Thank you for your coopration


您尚未执行命令

You haven''t executed the commands yet

SqlCommand cmd1 = new SqlCommand("select username from users",con);
SqlCommand cmd2 = new SqlCommand("select password from users",con);
if (cmd1.ToString() == textBox1.Text & cmd2.ToString() == textBox2.Text)



在您的调试窗口evalute cmd1.ToString()中,我忘记了最重要的内容(可能是类型名称?)

您需要执行命令以从db&中检索值.然后比较

无论如何,您实际上应该对此进行改进.创建一个使用参数< username>的存储过程.和< password>并调用该过程,并从您的表单中传入值.

您的SQL想要读取为

从用户名中选择用户名,其中用户名= @UserName和密码= @Password

目前,您只是从表中返回所有记录.上面的SQL将仅返回匹配的记录.



In your debug window, evalute cmd1.ToString(), I forget what that is off the top of my head (probably type name?)

You need to execute the command to retrieve the values from the db & then compare

You should really improve on this anyway. Create a stored procedure that takes params <username> and <password> and call the procedure, passing in the values from your form.

Your SQL wants to read like

select username from users where username = @UserName and password = @Password

At the moment, you''re just returning all records from your table. The above SQL will return only the matching record.


这篇关于请为我提供有关用户登录权限的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆