Add more controls to ASP.Net Login control using LayoutTemplate in C# and VB.Net

Last Reply one year ago By micah

Posted one year ago

Is it possible to have three contols  for login like Depertment, Email, and Password using web forms?.

I want to know how i can use this method to redirect to pages on login

    protected void ValidateUser(object sender, EventArgs e)
    {
        string department;
        int userId = 0;

        string constr = ConfigurationManager.ConnectionStrings[""].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand("Validate_UserS"))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Department", LoginINNOVATION);
                    cmd.Parameters.AddWithValue("@Email", LoginINNOVATION.UserName);
                    cmd.Parameters.AddWithValue("@Password", Encrypt(LoginINNOVATION.Password));
                    cmd.Connection = con;
                    con.Open();
                    department = Convert.ToString(cmd.ExecuteScalar());
                    con.Close();
                }

                if (!string.IsNullOrEmpty(department) && department != "-1" && department != "-2")
                {
                   FormsAuthentication.RedirectFromLoginPage(LoginINNOVATION.UserName, LoginINNOVATION.RememberMeSet);
                   Session["Department"] = department;
                }
                else
                {
                    Panel pn = (Panel)LoginINNOVATION.FindControl("Panel2");
                    pn.Visible = true;
                    Literal literal1 = (Literal)LoginINNOVATION.FindControl("ltText");
                    literal1.Text = "Username or password not correct.";

                    if (LoginINNOVATION.UserName.ToLower() == "Store 1")
                    {
                        Response.Redirect("~/Department/MainStore/RecievedStock.aspx");
                    }
                    else if (LoginINNOVATION.UserName.ToLower() == "Warehouse")
                    {
                        Response.Redirect("~/Department/MainWareHouse/WareHouse.aspx");
                    }
                    else if (LoginINNOVATION.UserName.ToLower() == "Admin")
                    {
                        Response.Redirect("~/Department/Admin/Admin.aspx");
                    }

 

You are viewing reply posted by: micah one year ago.
Posted one year ago

I CHANGED THE PROCEDUE IT WORKED, THANKS

I Changed from this

 

AS
BEGIN
      SET NOCOUNT ON;
      DECLARE @UserId INT
           
      SELECT @UserId = UserId
      FROM UserProfile
      WHERE Email = @Email AND [Password] = @Password
      
      IF @UserId IS NOT NULL
          BEGIN
                IF NOT EXISTS(SELECT UserId FROM UserActivation WHERE UserId = @UserId)
                    BEGIN
                          SELECT Department FROM UserProfile WHERE UserId = @UserId             
                    END
                ELSE
                    BEGIN
                          SELECT -2 -- User not activated.
                    END
          END
      ELSE
          BEGIN
                SELECT -1 -- User invalid.
          END
END

to this

 

 SET NOCOUNT ON;
      DECLARE @UserId INT
           
      SELECT @UserId = UserId
      FROM UserProfile
      WHERE Email = @Email AND Department=@Department AND [Password] = @Password
      
      IF @UserId IS NOT NULL
          BEGIN
                IF NOT EXISTS(SELECT UserId FROM UserActivation WHERE UserId = @UserId)
                    BEGIN
                          SELECT Department FROM UserProfile WHERE UserId = @UserId             
                    END
                ELSE
                    BEGIN
                          SELECT -2 -- User not activated.
                    END
          END
      ELSE
          BEGIN
                SELECT -1 -- User invalid.
          END
END