How to create login page with proper validation and remember me functionality using asp.net c#

How to create login page with proper validation and remember me functionality using asp.net c#

This example show you how to create login page/form funcationality.Here i am matching EmailID and Password.You can simple add this code in your project.I am giving proper table script in this tutorial,simply run script in your SQL Server and configure your web.config file.

Make a table for login details in SQL Server or run table script  in Sql server and insert EmailID and Password manually in table, after run this script table automatically create in your database.Script is here –

CREATE TABLE [dbo].[tblLogin](

[UserID] [int] IDENTITY(1,1) NOT NULL,

[EmailID] [varchar](50) NULL,

[Password] [varchar](50) NULL,

CONSTRAINT [PK_tblLogin] PRIMARY KEY CLUSTERED

(

[UserID] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON,ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

) ON [PRIMARY]

 

GO

SET ANSI_PADDING OFF

GO

After Create table in Sql Server then open Visual Studio and make a new website using C#, then add new item in website . After add new page in your website then add a label control and Textbox with the name txtEmailID and second is txtPassword and a button control in design page.

<%@ Page Language=”C#” AutoEventWireup=”true”CodeFile=”Login.aspx.cs” Inherits=”Login” %>

 

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN””http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml”>

<head runat=”server”>

<title></title>

<style type=”text/css”>

.style1

{

width: 45%;

}

.style2

{

width: 88px;

}

.style3

{

width: 207px;

}

</style>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<h2 style=”margin-left: 40px;margin-top:130px;”>Login Functionality</h2>

<table class=”style1″ style=”margin-left: 40px;background-color: #E7E7E7; padding: 10px; border: 1px solid Gray;

border-radius: 10px;”>

<tr>

<td class=”style2″>

Email ID :

</td>

<td class=”style3″>

<asp:TextBox ID=”txtEmailID” placeholder=”EmailID”runat=”server” Width=”193px”></asp:TextBox>

</td>

<td>

<asp:RequiredFieldValidator ID=”RequiredFieldValidator1″ErrorMessage=”Enter EmailID”

runat=”server” ControlToValidate=”txtEmailID”Style=”color: #FF0000; float: left;

font-style: italic;”></asp:RequiredFieldValidator>

<asp:RegularExpressionValidatorID=”RegularExpressionValidator1″ControlToValidate=”txtEmailID”

runat=”server” ErrorMessage=”Enter the correct EmailID”Style=”color: #FF0000;

margin-left: -95px; float: left;font-style: italic;”ValidationExpression=”\w+([-+.’]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*”></asp:RegularExpressionValidator>

</td>

</tr>

<tr>

<td class=”style2″>

Password :

</td>

<td class=”style3″>

<asp:TextBox ID=”txtPassword” placeholder=”Password”TextMode=”Password” runat=”server” Width=”192px”></asp:TextBox>

</td>

<td>

<asp:RequiredFieldValidator ID=”RequiredFieldValidator2″ErrorMessage=”Enter Password”

ControlToValidate=”txtPassword” runat=”server”Style=”color: #FF3300; font-style: italic”></asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td class=”style2″>

&nbsp;

</td>

<td class=”style3″>

<asp:Button ID=”btnLogin” runat=”server” Text=”Login”Width=”62px”

OnClick=”btnLogin_Click” />

<asp:CheckBox ID=”chkRememberme”style=”float:right;margin-top:4px;  margin-right: 12px;”Text=”Remember me?” runat=”server” />

</td>

<td>

&nbsp;

</td>

</tr>

<tr>

<td class=”style2″>

&nbsp;

</td>

<td class=”style3″>

<asp:Label ID=”lblErrorMsg” runat=”server” Style=”color: #FF0000″></asp:Label>

</td>

<td>

&nbsp;

</td>

</tr>

</table>

</div>

</form>

</body>

</html>

 

About the author

admin administrator

Leave a Reply