Click here to Skip to main content
15,918,889 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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";

}
}
Posted
Comments
F-ES Sitecore 3-Jun-15 5:13am    
Your Login_Check_sp is going to need to select the usertype field as well, then in your "login successful" segment you can look at

dt.Rows[0]["Usertype"]

to see what the value of that field is.
Member 11280947 3-Jun-15 6:06am    
How
F-ES Sitecore 3-Jun-15 6:15am    
We don't know what usertype is so can't say for sure. If it is a varchar then check if it equals "Administrator", if it is an ID or enum of some sort then check if it equals that value.
Member 11280947 3-Jun-15 6:18am    
Can You Explain More as code
Please
Member 11280947 3-Jun-15 6:19am    
Thank You By The Way

1 solution

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.
 
Share this answer
 
Comments
Andy Lanng 3-Jun-15 5:10am    
never store text based passwords

But I already know you've seen this one, OG ^_^
OriginalGriff 3-Jun-15 5:16am    
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900