• Our Services
  • Press Releases
  • Explore Us
  • Login
  • Our WordPress Plugin
  • Blog Posting Services
  • In LinkedIn
  • Our Code Repository
  • In Twitter
J
HARAPHULA
OneStop Shop of Information

Updates

  • Termites in House? Pest Control Services to Save Damage
    •
  • How to Buy Facebook Likes and boost your Reach?
    •
  • CNC Machining in Model Making Dubai for Prototypes
    •
  • Human Behavior in Men and Women Aged 18 to 35
    •
  • Best Nutrition for Active Working Dogs
    •
  • Why Homeowners Love Brown Granite Worktops for their Kitchens?
    •
  • Siding Repair in Cleveland – Why Timely Maintenance is Crucial for your Home?
    •
  • How to Transition to Toxic-Free Sanitary Pads Smoothly?
    •
  • Potassium Feldspar – A Comprehensive Guide
    •
  • What are Textile Chemicals and Why are they Important?
    •
  • How to Detect and Repair Leaks in PPRC Pipes and Fittings?
    •
  • Plumber Islington – MK Plumbers – Your Local Plumbing Experts
    •
  • Top Storage Sheds in Corowa – Reliable and Affordable Options
    •
  • Mastering Pest Control – Learn Online for a Sustainable Future
    •
  • Effective Strategies for Pest Control in Urban Environments
    •

ASP.NET Login form Example validating user from SQL Server Database

Microsoft Technologies
May 15, 2016
4 (1 votes)
ASP.NET Login form Example validating user from SQL Server Database ASP.NET Login form Example validating user from SQL Server Database
3 5 78
On-page friendly Custom Sidebar Widgets WP Plugin

Designing a Login form is not so easy as we are thinking. Modern login pages comes with various rich feature such as Validating User, Form Validation, Capcha or Remember Password. In this Login form Example demo app we are going to show you how to authenticate an user using records from SQL Server user table. To start with first you required to Create a user table in SQL Server.

Create a SQL Table for Users

To Create an user table which will store Login details such as UserID or Password your required to run the following Transact-SQL Query.

CREATE TABLE user_table (
id INT PRIMARY KEY, 
userid VARCHAR(255) NOT NULL, 
password VARCHAR(56)
);

Then insert some sample records.

In front-end Copy n Paste my default.aspx page Codes. Here I have 2 textbox Controls such as user id and password. To stop spam here I am using required field validation for both the fields. Additionally to valid an email id I am using ASP.NET RegularExpressionValidator validation control. Then in my form I have a submit button. Which submits the form to server using post method.

ASP.NET Login form Example

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>ASP.NET Login form Example</title>
<link rel="stylesheet" href="master.css" />
</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="lblMessage" runat="server"></asp:Label>
<input type="checkbox" value="remember-me" />&nbsp;Remember me<a href="#" class="pull-right margin-gap">Need help?</a>
</div>
</form> 
</body>
</html>

To valid user from SQL Server in Code behind file I am executing my business logics inside “btnVisitorLogin_Click” event. To connect and execute SQL query which will fetch data I imported the system files “System.Data” and “System.Data.SqlClient” in page header.

To establish a Connection I am creating a new instance for SQL Server Connection object. Which accepts connection string from my web.config file. Look at the below code to know how to declare connection string in web.config file.

<connectionStrings>
<add name="connStr" connectionString="Data Source=WINSERV;Initial Catalog=phase2;User ID=sa;Password=win#serv" providerName="System.Data.SqlClient"/>
</connectionStrings>

Here Data Source is my Database Server name. Initial Catalog is the Database name and User id, password is for the database user.

To compare user Credentials with database records here I am executing a command object and fetching user table records to a SQL DataReader. As you know datareader works like a pointer. Using a DataReader compare to a DataSet we can minimize the login time. To validate a user I am running a while loop until the end record of SQL DataReader “dr_pass”. For each record inside the while loop I am comparing the value with user password. In case it returns true I am allowing the user to redirect into the application dashboard page.

Default.aspx.vb

Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnVisitorLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVisitorLogin.Click

Dim oMyConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("connStr").ToString)
Dim oMyCommand As New SqlCommand("SELECT password, userid FROM user_table WHERE userid= '" & txtEmailID.Text & "' ", oMyConnection)
Dim dr_pass As SqlDataReader

oMyConnection.Open()
dr_pass = oMyCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

If Not dr_pass.HasRows Then
lblMessage.Text = "Invalid Email or Password."
End If

While dr_pass.Read
If Trim(txtPassword.Text) = dr_pass("password") Then
Session.Add("sess_uid", dr_pass("userid"))
Response.Redirect("../Dashboard.aspx")
End If
End While
End Sub
End Class

Login Form CSS Style (master.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; }

The above demo will run without CSS. But beauty attracts eyes. This is the cause I am with the above CSS classes. Apply this CSS to have a basic look. You modify it as per the mock-up.

Tags:ASP.NET Login form, ASP.NET Login Page, Database Basics, SQL Server Database, validating user from
Introduction to TCP/IP Model Layers for absolute Beginners
Responsive mobile first BootStrap 5 User Login page Example

Related Posts

  • Microsoft ASP.NET Interview Questions with Answers
  • List of frequently used common SQL Queries with Example
  • ASP.NET Login page example with Remember me Option
  • ADO.NET ExecuteNonQuery, ExecuteReader,…
  • Using LocalStorage Objects vs Web SQL Database in HTML5
  • Example of Resume for IT professionals to get their…
  • How to Design a Database? - Database Design for Beginners
  • PHP Treeview Example using data from MySQL Database
  • How to implement Paging and Sorting in ASP.NET…
  • Database Basics with Terminologies definition for Beginners
  • How to Make a Mobile App? - Full Guide for 2025
  • How to update records in a Gridview using Auto…
  • How to display various Files icon images in Datagrid rows?
  • How to use JavaScript function with ASP.NET CustomValidator?
  • Advanced AngularJS Interview Questions with Answers
  • How to display Excel File records in an ASP.NET Gridview?
  • Google like Autosuggestion Search Box using PHP,…
  • Why you Should Spend more Time Thinking related to…
  • How to implement Forms Authentication in ASP.NET?
  • How to add Search Filter in the Column Header of Gridview?
  • How to Store, Retrieve & Delete data from HTML5 IndexedDB?
  • Guide to eCommerce App Development - Benefits, Cost,…
  • Step-by-Step Guide to resetting Windows 7 password
  • AngularJS Form Validation (Required, Email, Number &…
  • Simple JavaScript Captcha Example (Client Side Captcha)
  • In a dynamic ASP.NET Gridview Delete row example
  • SQL Server Interview Questions for DBA professionals
  • Responsive mobile first BootStrap 5 User Login page Example
  • Top Mobile App Development Trends in 2025 - How…
  • Project Estimation Techniques for Software…

Popular Categories

  • Miscellaneous589
  • Digitalization298
  • Career Guide244
  • Indian Blog207
  • Business Book177
  • Health & Wellness168
  • Travel & Tourism132
  • Your Financial Advisor120
  • Real Estate Consulting111
  • Shopping97
  • Digital Marketing78
  • Blogging Techniques78
  • Home Remedies70
  • SEO Techniques67
  • Programming62
  • Automobiles57
  • Fashion & Fantacy53
  • Easy Recipes52

Our Popular Links

BootStrap Dropdown list with Checkbox Selected values will Show
Cheapest Cloud Hosting Services for Node.js Applications
How to keep Mashed Potatoes Warm all Dinner Long?
List of Linux Website Hosting Companies
Cheapest Hosting Plans for Joomla Blogs
Linux, PHP, MySQL Hosting Solutions for Freelancers
Hosting Plans for Large Enterprise Websites
Vitamin K Is the Solution Said to Fade Dark Circles
Hosting Limitations for Shared Servers
Why I will Choose VPS Hosting for Game Applications?
SSD Storage Hosting Services with High-Speed MySQL Servers

Our Web2 Blogs

Home Remedies
SEO Guest Posting
Digital Marketing
Learn Digital Marketing
Blog Posting Services
Blog for Bloggers
SEO Blog
Blog for Tourism

i20 Sidebar Widgets

Booking to Parking Locator Tools to Save big by Airport Hotel Parking
Booking to Parking Locator Tools to Save big by Airport Hotel Parking
When you are traveling through a plane, you are always confused where you will park your car at the airport either off-site parking, covered, uncovered...
Emotional Balance to People Skills the Perks of Traveling Solo
Emotional Balance to People Skills the Perks of Traveling Solo
Traveling is a fantastic experience, irrespective of where one decides to venture out. Most people like to tour places of interest in packs of friend...
Go Digital for your Travel Goals with Top 10 Travel Apps 2019
Go Digital for your Travel Goals with these Top 10 Travel Apps
Travelling has always been a remarkable frame of human life. And in this modern edge, the rage of travelling is a boon for a lot...
Crucial Tips for Maintaining Safety for Eyes for Observing Solar Eclipse
Crucial Tips for Maintaining Safety for Eyes while Observing Solar Eclipse
A total solar eclipse can be regarded as a rare natural phenomenon, which occurs at the time when the moon comes in between sun and...
Travel Industry Frauds - Methods for Preventing Travel Frauds
Travel Industry Frauds – Methods for Preventing Travel Frauds
With advancements in technology in recent years, it’s evident that fraudsters are stealing money from clients and travel agencies by using sophisticated methods. But according...
Expert Guidance and what to Experience of Desert Safari in Dubai
Expert Guidance and what to Experience of Desert Safari in Dubai
Planning a trip to Dubai? Look no further, as Dubai is the top destination for fun and entertainment. Desert safari, one of the most talked-about...
Interesting Adventure Vacations in the United States
Interesting Adventure Vacations in the United States
For some, getting away from the daily grind entails getting their adrenaline flowing on a rocky slope or 50 feet below the ocean’s surface. Others...
Top things to Do during the Tour of Dayara Bugyal Trek
Top things to Do during the Tour of Dayara Bugyal Trek
Dayara boasts some of our country’s greatest rolling meadows, which few people are aware of.It’s so big, broad and undulating that you don’t get anything...
Explore Northeast India with a Local and your new Travel Companion
Explore Northeast India with a Local and your new Travel Companion
Among the most attractive places resplendent with natural beauty, Northeast India is a wonderful tourist destination where you can Meet Locals and have an exciting...
7th Heaven the postcard Town Valparai and Aliyar Dam
7th Heaven the postcard Town Valparai and Aliyar Dam
A trip to Valparai had been on my mind for a long time. Set in the cradle of Anaimalai Hills in the Western Ghats, Valparai...
Cancun Parks, among the most beautiful places in Mexico
Cancun Parks, Among the Top Attractive Places in Mexico
Mexico is a great country, safe enough and where it is very easy to travel. Cancun Parks, one of the most demanded tourist activities, keeps...
Things I need to Take before Traveling with a Group
Things I need to Take before Traveling with a Group
Traveling with a Group? You are the holiday расkаgеrѕ dream! Imagine bеing аblе tо оfflоаd bulk аirlinе ѕеаtѕ, rail passes аnd еntеrtаinmеnt расkаgеѕ in оnе...

New Releases

YouTube Advertising Advantages, Limitations and best Practices
November 30, 2025

YouTube Advertising Advantages, Limitations and best Practices

YouTube has become one of the most influential digital platforms for advertising, offering businesses a dynamic way to reach global audiences. With billions of users…

Beyond the Mirror: The Rise of Preventive Skincare in Modern Wellness
November 24, 2025
Beyond the Mirror: The Rise of Preventive Skincare in Modern Wellness
WordPress Custom plugin Development Tutorial with Sample Codes
November 24, 2025
WordPress Custom plugin Development Tutorial with Sample Codes
b2b Email Marketing jobs and ZOHO Campaigns for professionals
July 7, 2025
b2b Email Marketing jobs and ZOHO Campaigns for professionals
YouTube Marketing Techniques to minimize Advertising Costs
July 2, 2025
YouTube Marketing Techniques to minimize Advertising Costs
Natural Hair Plantation for Women of any Age no Surgery
July 1, 2025
Natural Hair Plantation for Women of any Age with no Surgery
Eyeliner for Hooded Eyes to apply before applying Eyeshadow
July 1, 2025
Eyeliner for Hooded Eyes to apply before applying Eyeshadow
Comparing Paid and Free Website Builder for Small Business
July 1, 2025
Comparing Paid and Free Website Builder for Small Business
Google Search Console for SEO Tools for every Webmaster
July 1, 2025
Google Search Console for SEO Tools for every Webmaster
Digital Marketing Guest Post best practices to boost Sales
July 1, 2025
Digital Marketing Guest Post best practices to boost Sales
Deep Stretch Marks on Thighs and Belly during Pregnancy
June 26, 2025
Deep Stretch Marks on Thighs and Belly areas during Pregnancy
Fade Pregnancy Stretch Marks appear as Streaks or Lines on the Skin
June 26, 2025
Fade Pregnancy Stretch Marks appear as Streaks or Lines on the Skin
The best Guest Posting Website to boost your Online Presence
June 26, 2025
The best Guest Posting Website to boost your Online Presence
Digital Marketing Firms for Startup WordPress Blogs
June 25, 2025
Hi-Tech Digital Marketing Firms for Startup WordPress Blogs
Best Foods and 7 Day Diet Plan for Weight Loss help for Housewives
June 25, 2025
Prescribed Best Foods with 7 Day Diet Plan for Weight Loss Journey
Advanced Stage 3 Breast Cancer in Men and Women
June 25, 2025
Advanced Stage 3 Breast Cancer in Men and Women but Treatable
Explain Digital Marketing to Content Marketers for Leads
June 25, 2025
Explain Digital Marketing to Content Marketers for Sales Leads
Best Digital Marketing Agencies to boost AdSense Earning
June 24, 2025
Best Digital Marketing Agencies to boost AdSense Earning
explore us...
On-page SEO booster,
Google Friendly,
XML based
PHP/WP Sidebar
FREE Widgets
demo

OUR FACILITIES

  • Login
  • Our Background
  • Privacy
  • WordPress.org

CONTACT INFO

  • Reach Us
  • WhatsApp +919096266548

OUR SERVICES

  • Blog Posting Opportunity
  • *.fig, *.psd 2 html
  • Video Ads Designing
  • Setup your WordPress Blog
  • Optimizing Google PageSpeed
  • b2b Gmail IDs

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.