How to make login in .NET
Published: 2022-05-08 17:27:26

##Login.cs

```c#
    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace login
{
    public partial class login : System.Web.UI.Page
    {
        public object LoginStatus1 { get; private set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) 
            {
                int ViewstateVal = 1;
                

                if (ViewState["count"] != null)
                {
                    ViewstateVal = Convert.ToInt32(ViewState["count"]) + 1;
                    
                    ViewState["count"] = ViewstateVal.ToString();
                }
                else { ViewState["count"] = "1"; }

                TextBox1.Text = ViewstateVal.ToString();
                ViewState["count"] = ViewstateVal.ToString();
            }

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            bool verify = false;
            verify = MyAuthenticationLogic(Login1.UserName, Login1.Password);
            e.Authenticated = verify;
            if (e.Authenticated == true)
            {
               
                HttpCookie c1 = new HttpCookie("loginInfo");
                c1["Name"] = Login1.UserName;
                c1["Password"] = Login1.Password;
                Response.Cookies.Add(c1);

                Server.Transfer("redirect.aspx?username=" + Login1.UserName + "&password=" + Login1.Password, true);
            }
            else{ 
                errMsg.LoginText = "Enter the correct Credentials"; 
            }
        }
        protected bool MyAuthenticationLogic(string username, string password)
        {
            if (username == "Hrushikesh" && password == "CodeMaster")
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        protected void btn1_Click(object sender, EventArgs e)
        {
            Server.Transfer("redirect.aspx?username=" + Login1.UserName + "&password=" + Login1.Password, false);
        }
    }
    
}
```

Register.cs

```c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace login
{
    public partial class redirect : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = Request.QueryString["Username"];
            string password = Request.QueryString["password"];

            msgTxt.Text = "Welcome " + username + " Your Password is : " + password;

            HttpCookie c1 = Request.Cookies["loginInfo"];
            lbl1.Text ="Passord Is : "+ c1["Password"];
        }
    }
}
```

## ScreenShots

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqu6cwst79qc7v3yxw18.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l6byhrxyvyro70rwlua2.png)

[Read More](https://firebasestorage.googleapis.com/v0/b/statictube-5ddae.appspot.com/o/files%2Flogin.zip?alt=media&token=ff01b8c2-cda8-485f-a0b4-1472aab341a9)