Table and form design:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="User Name"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Login" />
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
public partial class login : System.Web.UI.Page
{
SqlConnection con = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
con.ConnectionString = ConfigurationManager.ConnectionStrings["abhishek"].ConnectionString;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
}
private Int32 checkuser(String U, String P)
{
SqlCommand cmd = new SqlCommand("Logincheck",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Username", SqlDbType.VarChar,50).Value = U;
cmd.Parameters.Add("@Password", SqlDbType.VarChar,50).Value = P;
cmd.Parameters.Add("@status", SqlDbType.Int);
cmd.Parameters["@status"].Direction = ParameterDirection.ReturnValue;
cmd.ExecuteNonQuery();
Int32 K = Convert.ToInt32(cmd.Parameters["@status"].Value);
cmd.Dispose();
return K;
}
protected void Button1_Click(object sender, EventArgs e)
{
Int32 d= checkuser(TextBox1.Text, TextBox2.Text);
if (d == -1)
{
Label3.Text = "Wrong User";
}
if (d == -2)
{
Label3.Text = "Wrong Password";
}
if (d == 1)
{
Label3.Text = "Login Successful";
}
}
}
0 comments:
Post a Comment