• Login
  • Our WordPress Plugin
  • Blog Posting Services
  • In Twitter
  • In LinkedIn
J
HARAPHULA
OneStop Shop of Information

Updates

  • Why Web2 Guest Posts Backlinks matters for Google Ranking?
    •
  • How Paid Guest Posting Services Help for SEO Backlinks?
    •
  • Why Guest Posting is a best approach to boost Products Sales?
    •
  • Do-follow links from Guest Posting how affecting Ranking
    •
  • Free Guest Posting in LinkedIn or Medium Accelerate Indexing
    •
  • Should I go for paid Guest Posting with No-follow links?
    •
  • Tricks for Lead Generation using Guest Posting deep links
    •
  • How Guest Posting Services useful for SEO Backlinks & Ranking?
    •
  • Why I will Choose Link Insertion in place of fresh Guest Posting with link?
    •
  • Quality Backlinks or Lead Generation when to use Guest Posting Service?
    •

ASP.NET Login page example with Remember me Option

Microsoft Technologies
May 15, 2016
3.7 (3 votes)
ASP.NET Login page example with Remember me Option ASP.NET Login page example with Remember me Option
2 5 92
Tricks to Spy on your Friends WhatsApp Messages

During we develop a product its always wise to save user time. Think about a login page. Here for Consecutive logins it is much better if we will store user Login Credentials. Using which System will remember the user id and password for next login. In this demo app I am creating a ASP.NET login page with “Remember me” Option.

The logic behind is so simple “During a user login to the System I am storing his/her user id and password to a Cookie. Then under page load event checking is Cookie exists. If so taking user id and password from the Cookie”.

Login.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Login.aspx.vb" Inherits="Login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Demo Login App</title>
<style type="text/css">
#frmLogin { max-width: 300px; margin: 0 auto; padding-top: 120px; }
.formControl { font-family: Verdana; font-size: 12px; }
.loginDiv { width:300px; margin-top: 20px; padding: 20px 20px 20px 20px; background-color: #f7f7f7; -moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3); -webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3); box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3); } 
.rounded { border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; }
</style>
</head>
<body>
<form id="frmLogin" runat="server">
<div class="loginDiv rounded">
<div class="formControl">
Email ID&nbsp;<span style="color: Red;">*</span>
</div>
<div class="formControl">
<asp:TextBox ID="txtEmailID" runat="server" Width="100%"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmailID" runat="server" ControlToValidate="txtEmailID"
Display="Dynamic" ErrorMessage="Email should not be blank.<br />"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmailID" runat="server" ControlToValidate="txtEmailID"
Display="Dynamic" ErrorMessage="Enter a valid Email ID.<br />" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</div>
<div class="formControl">
Password&nbsp;<span style="color: Red;">*</span>
</div>
<div class="formControl">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="100%"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="txtPassword"
Display="Dynamic" ErrorMessage="Password should not be blank."></asp:RequiredFieldValidator>
</div>
<asp:Button ID="btnVisitorLogin" runat="server" Text="Login" />
<asp:Label ID="lblMsg" runat="server"></asp:Label>
<asp:CheckBox ID="chkNextLogin" runat="server" />&nbsp;Remember me<a href="#" class="pull-right margin-gap">Need
help?</a>
</div>
</form>
</body>
</html>

For security reason in Code behind I added my EncryDecry.vb Class from app_code/vb. To execute vb code inside vb folder of app_code I Configured my web.config.

Login.aspx.vb

Imports System.Web.Security
Imports System.Data
Imports System.Data.SqlClient

Partial Class Login
Inherits System.Web.UI.Page

Dim LoginSqlConn As New SqlConnection(ConfigurationManager.AppSettings.Get("DBKey").ToString())

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
txtEmailID.Focus()

'Check if the browser support cookies
If Request.Browser.Cookies Then
'Check if the cookies with name PBLOGIN exist on user's machine
If Request.Cookies("PBLOGIN") IsNot Nothing Then
'Pass the user name and password to the VerifyLogin method
Me.VerifyLogin(Request.Cookies("PBLOGIN")("UNAME").ToString(), Request.Cookies("PBLOGIN")("UPASS").ToString())
End If
End If
End If
End Sub

Protected Sub btnVisitorLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVisitorLogin.Click
'Decrypt the Password & UserID from Database
Dim EncrDecr As New EncryDecry

'Validation Checking Aginest Submission
If rfvPassword.IsValid And rfvEmailID.IsValid Then
'Clear Invalid login Message Label
lblMsg.Text = ""

'Temporary SecuredUniqueKey
Dim UniKey As String = "FCPH6-BPK27-2V4MR"

'Login Checking command in shape of a Stored Procedure that returns Record Count
Dim LoginCommand As New SqlCommand("USP_LoginCheck", LoginSqlConn)
LoginCommand.CommandType = CommandType.StoredProcedure

'Pass Parameter to Stored Procedure
LoginCommand.Parameters.Add("@UserID", SqlDbType.NVarChar, 256).Value = EncrDecr.TripleDESEncode(Trim(txtEmailID.Text), "RC2")
LoginCommand.Parameters.Add("@Passcode", SqlDbType.NVarChar, 256).Value = EncrDecr.TripleDESEncode(Trim(txtPassword.Text), "RC2")
LoginCommand.Parameters.Add("@SecuredUniqueKey", SqlDbType.NVarChar, 256).Value = UniKey
LoginCommand.Parameters.Add("@Status", SqlDbType.NVarChar, 20).Value = "Active"

Dim RecordCNT As Integer = 0

Try
Dim LoginDataReader As SqlDataReader
LoginSqlConn.Open()
LoginDataReader = LoginCommand.ExecuteReader
If LoginDataReader.Read Then
RecordCNT = Convert.ToInt32(LoginDataReader(0).ToString())
End If
Catch ex As Exception
Response.Write(ex.ToString())
Finally
LoginSqlConn.Close()
End Try

'Login Checking using the return int value of USP_LoginCheck stored procedure
If (RecordCNT = 1) Then
Me.VerifyLogin(EncrDecr.TripleDESEncode(Trim(txtEmailID.Text), "RC2"), EncrDecr.TripleDESEncode(Trim(txtPassword.Text), "RC2"))
ElseIf (RecordCNT > 1) Then
lblMsg.Text = "Invalid Login Credentials"
'Implement 5 Login Attempts of Account Lock
ElseIf (RecordCNT < 1) Then
lblMsg.Text = "Invalid Login Credentials"
'Implement 5 Login Attempts of Account Lock
End If
End If
End Sub

Private Sub VerifyLogin(ByVal UserID As String, ByVal Password As String)
Dim LoginDetailsCommand As New SqlCommand("USP_LoginDetails", LoginSqlConn)
LoginDetailsCommand.CommandType = CommandType.StoredProcedure

'Pass Parameter to Stored Procedure
LoginDetailsCommand.Parameters.Add("@UserID", SqlDbType.NVarChar, 256).Value = UserID
LoginDetailsCommand.Parameters.Add("@Passcode", SqlDbType.NVarChar, 256).Value = Password

Try
Dim LoginDetailsDR As SqlDataReader
LoginSqlConn.Open()
LoginDetailsDR = LoginDetailsCommand.ExecuteReader

If LoginDetailsDR.Read Then
Session("UserID") = LoginDetailsDR("PkUid")
Session("UserEmail") = UserID

Session("FirstName") = LoginDetailsDR("FirstName")
Session("LastName") = LoginDetailsDR("LastName")

Session("RootPath") = Server.MapPath("../")

'Using form authentication redirect the page to the Default.aspx
FormsAuthentication.RedirectFromLoginPage(Trim(txtEmailID.Text), True)

'check if remember me checkbox is checked on login
If (chkNextLogin.Checked) Then
'Check if the browser support cookies
If (Request.Browser.Cookies) Then
'Check if the cookie with name PBLOGIN exist on user's machine
If (Request.Cookies("PBLOGIN") Is Nothing) Then
'Create a cookie with expiry of 30 days
Response.Cookies("PBLOGIN").Expires = DateTime.Now.AddDays(30)
'Write username to the cookie
Response.Cookies("PBLOGIN").Item("UNAME") = UserID
'Write password to the cookie
Response.Cookies("PBLOGIN").Item("UPASS") = Password
Else
'If the cookie already exist then wirte the user name and password on the cookie
Response.Cookies("PBLOGIN").Item("UNAME") = UserID
Response.Cookies("PBLOGIN").Item("UPASS") = Password
End If
End If
End If
Else
lblMsg.Text = "Invalid Login Credentials"
End If
Catch ex As Exception
Response.Write(ex.ToString())
Finally
LoginSqlConn.Close()
End Try
End Sub
End Class

web.config

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="DBKey" value="Data Source=VIJAYSHANTI; uid=sa; pwd=tiger; database=CodeRND;"/>
</appSettings>
<connectionStrings/>
<system.web>
<compilation debug="true" strict="false" explicit="true">
<codeSubDirectories>
<add directoryName="VB"/>
</codeSubDirectories>
</compilation>
<authentication mode="Windows"/>
</system.web>
</configuration>

EncryDecry is the class which helps to convert user id and password to RC2 format. In-case an other user find out the cookie in client machine he or she can’t able to hack the original user.

EncryDecry.vb

Imports System.Security.Cryptography
Imports Microsoft.VisualBasic

Public Class EncryDecry

Public Function TripleDESEncode(ByVal value As String, ByVal key As String) As String
Dim des As New System.Security.Cryptography.TripleDESCryptoServiceProvider
des.IV = New Byte(7) {}
Dim pdb As New System.Security.Cryptography.PasswordDeriveBytes(key, New Byte(-1) {})
des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, New Byte(7) {})
Dim ms As New IO.MemoryStream((value.Length * 2) - 1)
Dim encStream As New System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write)
Dim plainBytes As Byte() = Text.Encoding.UTF8.GetBytes(value)
encStream.Write(plainBytes, 0, plainBytes.Length)
encStream.FlushFinalBlock()
Dim encryptedBytes(CInt(ms.Length - 1)) As Byte
ms.Position = 0
ms.Read(encryptedBytes, 0, CInt(ms.Length))
encStream.Close()
Return Convert.ToBase64String(encryptedBytes)
End Function

Public Function TripleDESDecode(ByVal value As String, ByVal key As String) As String
Dim des As New System.Security.Cryptography.TripleDESCryptoServiceProvider
des.IV = New Byte(7) {}
Dim pdb As New System.Security.Cryptography.PasswordDeriveBytes(key, New Byte(-1) {})
des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, New Byte(7) {})
Dim encryptedBytes As Byte() = Convert.FromBase64String(value)
Dim ms As New IO.MemoryStream(value.Length)
Dim decStream As New System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write)
decStream.Write(encryptedBytes, 0, encryptedBytes.Length)
decStream.FlushFinalBlock()
Dim plainBytes(CInt(ms.Length - 1)) As Byte
ms.Position = 0
ms.Read(plainBytes, 0, CInt(ms.Length))
decStream.Close()
Return Text.Encoding.UTF8.GetString(plainBytes)
End Function

End Class

Tags:ASP.NET Login Page, Cleaver UI developer, Login page Example, Remember me Option, Windows Authentication
Simple string to image based free PHP Captcha Code
Simple PHP pagination Example using MySQL records

Related Posts

  • How to implement Forms Authentication in ASP.NET?
  • WordPress Tricks to keep your Website Secure from Hacking
  • Responsive mobile first BootStrap 5 User Login page Example
  • ASP.NET Login form Example validating user from SQL…
  • How to Check is Browser Cookie enabled or disabled…
  • How to Add Share button in WordPress blog?
  • IP Address Spoofing to DNS Spoofing Attacks in details
  • Project Estimation Techniques for Software…
  • Using HTML5 Application Cache for Offline Storage
  • How Followers Gallery helps for active Instagram…
  • Step-by-Step Guide to resetting Windows 7 password
  • Make Money with Google Adsense - Adsense Approval Trick
  • WordPress Tutorial for beginners - Learn the most…
  • How to install WordPress on XAMPP Web Server?
  • Simple JavaScript Captcha Example (Client Side Captcha)
  • A Multi Vendor B2C ECommerce Marketplace Website Design
  • Create, Remove or Read a PHP Cookie using Setcookie method
  • How to use JavaScript function with ASP.NET CustomValidator?
  • Has Instagram Blocked your Login for no Reasons? -…
  • Tricks to Draw CSS Triangle using DIV without Images
  • Random Password Generator Function using VB.NET
  • How to Start a WordPress blog with Hostgator & Godaddy?
  • Facebook for Business to drive massive visitors to your Blog
  • Optimize your WordPress Blog with these essential Plugins
  • How to Save image Offline using HTML5 Local Storage?
On-page SEO booster,
Google Friendly,
XML based
PHP/WP Sidebar
FREE Widgets
demo

Our Web2 Blogs

Business Hosting Provider
Hosting Shop
Hosting for WordPress Bloggers
Publishing Services
Indian Blog
Blog Posting Services

Popular Categories

  • Miscellaneous590
  • Digitalization298
  • Career Guide243
  • Indian Blog207
  • Business Book177
  • Health & Wellness167
  • Travel & Tourism132
  • Your Financial Advisor116
  • Real Estate Consulting111
  • Shopping97
  • Blogging Techniques75
  • Digital Marketing72
  • Home Remedies70
  • SEO Techniques67
  • Programming62
  • Automobiles57
  • Easy Recipes52
  • Fashion & Fantacy52

i20 Sidebar Widgets

4 different Types of Cancer associated with Body Functions
4 different Types of Cancer associated with Body Functions
Cancer is a terminal disorder which occurs around the body of a patient and specifically related to the organ. Patients suffering from cancer think that...
Types of Glaucoma and How to treated with them?
Types of Glaucoma and How to treated with them?
Glaucoma is one of the vision problems that are more often linked to people above the age of 60 years. It causes damage to the...
How to effectively Reduce Menopausal Symptoms?
How to effectively Reduce Menopausal Symptoms?
Menopause is a significant phase in every woman’s life as it ushers inevitable changes brought about by old age. Albeit normal, it signifies the end...
Whats Amazing a Good Sleep does to your Beauty
What’s Amazing a Good Sleep does to your Beauty
Sleep deprivation automatically relates to stress. Stress releases hormones called cortisol which can cause skin defects due to skin inflammation. Here skin inflammation can be...
What Is Cholera? Symptoms, Causes, Diagnosis
What is Cholera? Symptoms, Causes and Diagnosis
Cholera is a highly infectious disease that has affected millions worldwide. Despite advancements in healthcare, this age-old scourge continues to pose a significant threat in...
Frequently Asked Questions (FAQ) related to Baby Acne Problems
Frequently Asked Questions (FAQ’s) related to Baby Acne Problems
Baby Acne Problems is so common that every fifth child born get Baby Acne just a couple of weeks after the birth. Until now no...
What are the various Orthopedic Surgeons Treats?
What are the various Orthopedic Surgeons Treats?
Orthopedic Surgeons are devoted to the avoidance, diagnosis and treatment of disorders of the joints, bones, ligaments, joints, tendons and muscles. Required skills Orthopaedic surgeons...
Risks of Stacking to benefits of Stack or Bodybuilding Supplements
Risks of Stacking to benefits of Stack or Bodybuilding Supplements
There are many people who are using supplements. Some of them are using for bulking and some for cutting. Bodybuilders, athletes as well as people...
High Blood Pressure Symptoms & Signs in Men (High BP)
High Blood Pressure Symptoms & Signs in Men (High BP)
High blood pressure is a serious disease that can, after some time, damage the blood vessel walls and increase a person’s risk of heart attack,...
Cure Pimples and unwanted Red or Black Spots from Face
Cure Pimples and unwanted Red or Black Spots from Face
Due to several reasons we found pimples on our face areas. Pimple is an Odd smell. Nearly everyone hate pimples. Pimples & Pimple spots destroy...

New Releases

GoDaddy Wordpress Hosting Plans for Freelancers and Bloggers
June 13, 2025

GoDaddy WordPress Hosting Plans for Freelancers and Bloggers

To run a WordPress site efficiently, reliable hosting is essential. GoDaddy, a well-known name in the web hosting industry, offers specialized WordPress hosting plans designed…

Managed Hosting for WordPress and WooCommerce Websites
June 13, 2025
Managed Hosting for WordPress and WooCommerce Websites
Best Cloud Hosting providers NVMe Disk Space, 20 Lakhs Inodes
June 12, 2025
Best Cloud Hosting providers NVMe Disk Space, 20 Lakhs Inodes
Local Hosting for WordPress or Shared Server which is better
June 11, 2025
Local Hosting for WordPress or Shared Server which is better
Comparing AWS Hosting and GoDaddy Web Hosting Features
June 11, 2025
Comparing AWS Hosting and GoDaddy Web Hosting Features
GoDaddy WordPress Hosting Plans: A Comprehensive Overview
June 10, 2025
GoDaddy WordPress Hosting Plans: A Comprehensive Overview
VPS Hosting providers with vCPU Core, TB Bandwidth, NVMe Disk
June 10, 2025
VPS Hosting providers with vCPU Core, TB Bandwidth, NVMe Disk
Best Dedicated Server Hosting for Blog Website and Bloggers
June 10, 2025
Best Dedicated Server Hosting for Blog Website and Bloggers
Fastest Web Hosting for Small and Medium Size Businesses
June 10, 2025
Fastest Web Hosting for Small and Medium Size Businesses
Best Cloud Hosting providers for Small Scale Businesses
June 10, 2025
Best Cloud Hosting providers for Small Scale Businesses
Best Cloud Server Hosting Services for Personal Use or Reselling
June 10, 2025
Best Cloud Server Hosting Services for Personal Use or Reselling
Good Hosting Plans for your Personal Portfolio or Blogs
June 10, 2025
Good Ecommerce Hosting for your Personal Portfolio or Blogs
Ecommerce Website Hosting for Small Business and NGOs
June 10, 2025
Ecommerce Website Hosting for Small Business and NGOs
Best and Cheapest Reseller Hosting for WordPress Freelancers
June 10, 2025
Best and Cheapest Reseller Hosting for WordPress Freelancers
Cheapest Dedicated Server Hosting for Entrepreneurs and Enterprises
June 10, 2025
Cheapest Dedicated Server Hosting for Entrepreneurs and Enterprises
Best Web Hosting for Beginners to Host their WordPress Blog
June 10, 2025
Best Web Hosting for Beginners to Host their WordPress Blog
Best Web Hosting for Small Businesses Cost-Effective Solutions
June 10, 2025
Best Web Hosting for Small Businesses Cost-Effective Solutions
WordPress Migration? Time to Choose Hosting Provider wisely
June 9, 2025
WordPress Migration? Time to Choose Hosting Provider wisely
explore us...

OUR FACILITIES

  • Login
  • Our Background
  • Privacy
  • WordPress.org

CONTACT INFO

  • Do WhatsApp
  • Reach us

SEO GUEST POSTING

Do you like to publish your Stories near Quality Audiences? If so, “OneStop Shop” is the best platform for you. We are one among the vastly growing Indian Blog. Reach us to publish your Stories with lifelong No-Follow links.

WHY ONESTOP?

We are here to bring high Quality Information. As a multi-niche platform we have spend several years for Collecting various useful Stories. Dream to establish a domain where from you can get all your day today required information. We covers Animals to Zoology.
©2014-2025 JHARAPHULA, ALL RIGHTS RESERVED.
Show Buttons