Asp.net Login form using c#

Saturday, January 19, 2013










LOgin in Aspx using c#

Dafult.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text="Enter your roll number"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server" Text="Enter your roll number"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Login" />
</td>
</tr>
</table>
<div>

</div>
</form>
</body>
</html>

Default.aspx.cs:

May b you have a better idea to do this , but if you don't have have it ...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{


}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection a = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\Faran\Documents\Visual Studio 2008\WebSites\WebSite2\App_Data\login.mdf';Integrated Security=True;User Instance=True");
a.Open();
string query = "select count(*) from user_login where Roll='" + TextBox1.Text + "'";
SqlCommand sc = new SqlCommand(query, a);
int temp = Convert.ToInt32(sc.ExecuteScalar().ToString());
if (temp == 1)
{
string query2 = "select login_id from user_login where login_id='" + TextBox2.Text + "'";
SqlCommand sc2 = new SqlCommand(query2, a);
string log = Convert.ToString(sc2.ExecuteScalar());


if (log==TextBox2.Text)
{
Response.Write("welcome");
}
else
{
Response.Write("Invalid password ...!");
}
}
else
{
Response.Write("Invalid user name ...!");

}

}

}

Database:

Database name :login
Table name : user_login
column 1 : Roll
Column 2 : login_id

Thnx

No comments:

Post a Comment

 

Most Reading