如何检查用户是否是超级用户 [英] how to check if user is SuperUser or not

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

问题描述

我有一个登录表,其中我有四列id,用户名,密码和SuperUser。当我登录时,我想向普通用户和整个页面显示特定页面给超级用户。我尝试的是:



 protected void LoginButton_Click(object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(@数据源= ashish-pc \;初始目录= HMS;集成安全性=真);
con.Open();
SqlCommand cmd = new SqlCommand(select * from Login where UserName = @ UserName and Password = @ Password,con);
cmd.Parameters.AddWithValue(@ UserName,UserName.Text.Trim());
cmd.Parameters.AddWithValue(@ Password,Password.Text.Trim());
cmd.Parameters.Add(IsSuperUser);


SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet dt = new DataSet();

da.Fill(dt);
if(dt.Tables [0] .Rows.Count> 0)
{



Session [UserName] = UserName.Text ;
Session.Timeout = 1;

//会话[登录] =
Response.Redirect(/ Home.aspx);

}
else
{
Response.Write(用户名和密码无效);
}
con.Close();
}





请帮助

解决方案

Ass UserTypeType Column使用datataype varchar或char的数据表。

为超级用户保存'S'

为普通用户保存'N'



现在登录时添加支票如

  if (UserType == '  S'
{
// 此i ssuper用户
}
else
{
// 这是普通用户
}


I have a login table in which i have four columns id, username, password and SuperUser. when i login i want to show specific pages to normal user and whole pages to superuser. what i tried is:

protected void LoginButton_Click(object sender, EventArgs e)
        {
            SqlConnection con=new SqlConnection(@"Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from Login where UserName=@UserName and Password=@Password", con);
            cmd.Parameters.AddWithValue("@UserName", UserName.Text.Trim() );
            cmd.Parameters.AddWithValue("@Password", Password.Text.Trim());
            cmd.Parameters.Add("IsSuperUser");

            
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet dt = new DataSet();
            
            da.Fill(dt);
            if (dt.Tables[0].Rows.Count>0)
            {
                

                
                Session["UserName"] = UserName.Text;
                Session.Timeout = 1;

                //Session["Login"] =     
                Response.Redirect("/Home.aspx");
                
            }
            else 
            {
                 Response.Write("Invalid username and password");
            }
            con.Close();
        }



please help

解决方案

Ass UserType Column in you data table with datataype varchar or char.
Save 'S' for SuperUser
Save 'N' for Normal User

Now when log in add check like

if(UserType == 'S')
{
//This i ssuper user
}
else
{
//this is normal user
}


这篇关于如何检查用户是否是超级用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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