Step 1-Add a Login1.aspx Page in Application.And Add below Code for User Input-
Step 2-Add below code on Button Click event-<body><form id="form1" runat="server"><div><table class="auto-style1"><tr><td colspan="2"> </td></tr><tr><td class="auto-style3"> </td><td> </td></tr><tr><td class="auto-style3"> </td><td> </td></tr><tr><td class="auto-style3"> </td><td> </td></tr><tr><td class="auto-style3"> </td><td> </td></tr><tr><td class="auto-style2" colspan="2"><strong>LOGIN HERE</strong></td></tr><tr><td class="auto-style3"> </td><td> </td></tr><tr><td class="auto-style3"> </td><td> </td></tr><tr><td class="auto-style4">UserName</td><td><asp:TextBox ID="txtname" runat="server" Width="229px"></asp:TextBox></td></tr><tr><td class="auto-style4">Password</td><td><asp:TextBox ID="txtpassword" runat="server" TextMode="Password" Width="230px"></asp:TextBox></td></tr><tr><td class="auto-style3"> </td><td> </td></tr><tr><td class="auto-style3"> </td><td><asp:Button ID="btnLogin" runat="server" OnClick="btnLogin_Click" Text="Login" Width="82px" /> <asp:Button ID="btnRegister" runat="server" OnClick="btnRegister_Click" Text="New User Register Here" Width="166px" /></td></tr></table></div></form></body>
BusinessLogic bl = new BusinessLogic();
BusinessObject bo = new BusinessObject();
protected void btnLogin_Click(object sender, EventArgs e)
{
string username = txtname.Text;
string password = txtpassword.Text;
int a = bl.ballogin(username, password);
txtname.Text = "";
txtpassword.Text = "";
if (a == 1)
{
Session["username"] = username;
Response.Redirect("Project.aspx");
}
}Step 3-Add A class Library in Application and Add Class in Class Library name is BussinessLogic and Bussines Object,add Below Code in BissinessLogic Class-
Step 4-Add Below Code in Data Layer Logic class.public int ballogin(string username, String password){try{int a = dal.userLogin(username, password);if (a == 1){return 1;}else{return 0;}}catch (Exception e){e.GetType();}return 0;}
Step 5-Add below Connection string in Data access class-public int userLogin(string username, string password){try{con.Open();SqlCommand cmd = new SqlCommand("select count(*) from Registration where Name='" + username + "'and password='" + password + "'",con);// cmd.ExecuteScalar();//return 1;int a = Convert.ToInt32(cmd.ExecuteScalar());return a;}catch (Exception e){throw e;}finally{con.Close();}}
Step 6-After Completion this Create Table and add some l data and use this code for login with application and authenticate user from databaseSqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=ProjectTest;Integrated Security=True");
No comments:
Post a Comment