PRE I'm using SQLExpress to store information.
I have a very basic user set-up in my app. I have a Login table that contains only three fields, these are Username, Password and Security Level. There are only three security levels; High, Medium and Low.
On my login form, I have the following code to save the user that is logging into a Settings.Default[]
, so I can read it later.
private void Loginbtn_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=MySupportHub;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter(@"SELECT * FROM [dbo].[Login] Where Username='" + usernameTextBox.Text + "' and Password='" + passwordTextBox.Text + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows.Count == 1)
{
Settings.Default["CurrentUserName"] = usernameTextBox.Text;
Settings.Default.Save();
this.Hide();
Home home = new Home();
home.Show();
}
else
{
MessageBox.Show("Invalid Username and/or Password..!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Clearbtn_Click(sender, e);
}
}
Then on the Home page, I have the following code to get the value and display the current logged in user in the bottom status bar. On page load.
//Identify and display current logged in user
CurrentUser.Caption = Settings.Default["CurrentUserName"].ToString();
What I would like to be able to do now is check the current logged in users security level (User value would be stored here "CurrentUser.Caption
" on the main form) and be able to disable features like creating a new user etc.
So I would need to be able to read the CurrentUser.Caption
value, check that against the (SQL Express) [dbo].[Login] table and find the user's security level and limit features based on the result.
Any help would be appreciated.
Thanks
Phil