jeudi 1 mai 2014

c# - vérifier si l'utilisateur est un utilisateur de base ou l'admin sans adhésion - Stack Overflow


I am a bit stuck in my project. I have a login page, 2 text boxes where you enter Username and Password. What I'm having trouble with is that I need to determine if the user that logs in, is a basic user or an administrator. If it's a basic user then go to menu 1 (for basic user) and if its an admin then go to menu 2 (for admin). In my database I have the column 'Permission' where the user is either a Basic user or an admin. So basically, how do I check to see whether the user thats attempting to sign in is an "Admin" or BasicUser" under the Permission column. Any help would be greatly, greatly appreciated!




maybe something like this?


        //create a SqlConnection
string connStr = "your connection string";
SqlConnection conn = new SqlConnection(connStr);

//Create a database reader
conn.Open();
// username column ↓ username textbox ↓
string sql = "select * from users where username='" + usernameTextBox.Text + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();

//Assume that the permission column has true for Admin and false for Basic user
bool permission = false;

while (reader.Read())
{
//reads permission column
permission = reader["permission"].ToString();
}


if (permission == true)
{
//go to admin menu
}
else
{
//go to basic users menu
}



For authentication : Check for the user name and password in the database. If the user exists (authenticated) then return the permission column value from database. You will do this using stored procedure.


Based on this value Assuming the permission column has 1 - Admin and 0 - Basic


if (PermissionValue )
{
// go to Admin menu
}
else {
// go to Basic menu
}


I am a bit stuck in my project. I have a login page, 2 text boxes where you enter Username and Password. What I'm having trouble with is that I need to determine if the user that logs in, is a basic user or an administrator. If it's a basic user then go to menu 1 (for basic user) and if its an admin then go to menu 2 (for admin). In my database I have the column 'Permission' where the user is either a Basic user or an admin. So basically, how do I check to see whether the user thats attempting to sign in is an "Admin" or BasicUser" under the Permission column. Any help would be greatly, greatly appreciated!



maybe something like this?


        //create a SqlConnection
string connStr = "your connection string";
SqlConnection conn = new SqlConnection(connStr);

//Create a database reader
conn.Open();
// username column ↓ username textbox ↓
string sql = "select * from users where username='" + usernameTextBox.Text + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();

//Assume that the permission column has true for Admin and false for Basic user
bool permission = false;

while (reader.Read())
{
//reads permission column
permission = reader["permission"].ToString();
}


if (permission == true)
{
//go to admin menu
}
else
{
//go to basic users menu
}


For authentication : Check for the user name and password in the database. If the user exists (authenticated) then return the permission column value from database. You will do this using stored procedure.


Based on this value Assuming the permission column has 1 - Admin and 0 - Basic


if (PermissionValue )
{
// go to Admin menu
}
else {
// go to Basic menu
}

0 commentaires:

Enregistrer un commentaire