How do I set different login paths depending on the user credentials provided.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Indra99
    New Member
    • Sep 2016
    • 2

    How do I set different login paths depending on the user credentials provided.

    Hi , I have a Login page and want that if the user credentials provided are those of the Administrator(U sername = Administrator) then a Window Form App Page called "AdminPage" should open up. Else another Window Form App called "Main_Page" should open up.

    What I have tried:

    Hide Expand Copy Code
    try
    {
    SqlConnection cn = new SqlConnection(" Data Source=PV10\\LO CALSERVER;Initi al Catalog=SmallSo ftwareDB;Integr ated Security=True;P ooling=False");
    SqlCommand cmd = new SqlCommand("sel ect * from UserCredentials where Username='" + textBox1.Text + "' and Password='" + textBox2.Text + "'", cn);
    SqlDataReader dr;
    cn.Open();
    dr = cmd.ExecuteRead er();
    int cnt = 0;
    while (dr.Read())
    {
    cnt++;
    }
    if (cnt == 1)
    {
    MessageBox.Show ("Successful Login...", "Message", MessageBoxButto ns.OK, MessageBoxIcon. Information);
    string query = "select Username, Password from UserCredentials where Username='Admin istrator";
    SqlCommand cmdA = new SqlCommand(quer y, cn);
    dr = cmdA.ExecuteRea der();
    int k = 0;
    while (dr.Read())
    {
    k++;
    }
    if (k == 1)
    {
    AdminPage A_P = new AdminPage();
    A_P.Tag = this;
    A_P.Show(this);
    Hide();
    }
    Main_Page Mp = new Main_Page();
    Mp.Tag = this;
    Mp.Show(this);
    Hide();
    cn.Close();
    textBox1.Clear( );
    textBox2.Clear( );
    }
    else
    {
    MessageBox.Show ("Invalid UserName or Password", "Message", MessageBoxButto ns.RetryCancel, MessageBoxIcon. Warning);
    textBox1.Clear( );
    textBox2.Clear( );
    }
    }
    catch (Exception err)
    {
    MessageBox.Show (err.Message, " ", MessageBoxButto ns.OK, MessageBoxIcon. Warning);
    }
Working...