如何检查用户类型是否=管理员或其他 [英] How Can check If The User Type is = Administrator or Other

查看:84
本文介绍了如何检查用户类型是否=管理员或其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建表,[用户名]

,[FullName]

,[PasswordUser]

,[Usertype]



此登录表

如何检查用户类型是否=管理员或其他

按此代码









DataTable dt = new DataTable();

SqlDataAdapter adp = new SqlDataAdapter();

尝试

{

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [conStr] .ConnectionString);

SqlCommand cmd = new SqlCommand(Login_Check_Sp,con);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue(@ username, txtUserName.Text.Trim());

cmd.Parameters.AddWithValue(@ pwd,txtPwd.Text.Trim());

adp.SelectCommand = cmd ;

adp.Fill(dt);

cmd.Dispose();

if(dt.Rows.Count> 0)

{

lblStatus.Text =登录成功;

}

其他

{

lblStatus.Text =错误的用户名/密码;



}

}

I create table ,[Username]
,[FullName]
,[PasswordUser]
,[Usertype]

this Login Table
How Can check If The User Type is = Administrator or Other
By This Code




DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter();
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
SqlCommand cmd = new SqlCommand("Login_Check_Sp", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", txtUserName.Text.Trim());
cmd.Parameters.AddWithValue("@pwd", txtPwd.Text.Trim());
adp.SelectCommand = cmd;
adp.Fill(dt);
cmd.Dispose();
if (dt.Rows.Count > 0)
{
lblStatus.Text = "Login Successfull";
}
else
{
lblStatus.Text = "Wrong Username/Password";

}
}

推荐答案

规则一:永远不要存储基于文本的密码。请参阅此处:密码存储:如何操作。 [ ^ ]



所有你需要做的就是查看你的DataTableUserType中的列,检查用户是否是管理员...但是你存储的内容的具体细节tehre只为你所知 - 它可以是一个字符串,一个整数映射到代码中的枚举,任何东西。
Rule one: Never store text based passwords. See here: Password Storage: How to do it.[^]

And all you have to do is look at the column in your DataTable "UserType" and check if the user is an admin...but the exact details of what you store in tehre are known only to you - it could be a string, an integer which maps to an enum in your code, anything.


这篇关于如何检查用户类型是否=管理员或其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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