• 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 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
5 5 82
Tricks to Spy on your Friends WhatsApp Messages

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

  • How to implement Forms Authentication in ASP.NET?
  • Responsive mobile first BootStrap 5 User Login page Example
  • How to install WordPress on XAMPP Web Server?
  • WordPress Tricks to keep your Website Secure from Hacking
  • Simple JavaScript Captcha Example (Client Side Captcha)
  • ASP.NET Login page example with Remember me Option
  • Project Estimation Techniques for Software…
  • How to Design a Database? - Database Design for Beginners
  • How to use JavaScript function with ASP.NET CustomValidator?
  • Database Basics with Terminologies definition for Beginners
  • IP Address Spoofing to DNS Spoofing Attacks in details
  • How to Check is Browser Cookie enabled or disabled…
  • List of frequently used common SQL Queries with Example
  • JQuey AJAX File Upload Example using PHP Server
  • AngularJS Form Validation (Required, Email, Number &…
  • Using HTML5 Application Cache for Offline Storage
  • SQL Server Interview Questions for DBA professionals
  • Create, Remove or Read a PHP Cookie using Setcookie method
  • How to Start a WordPress blog with Hostgator & Godaddy?
  • Simple string to image based free PHP Captcha Code
  • Script for PHP upload image file to Server using…
  • AngularJS Assessment Questionnaires for Trainees to Evaluate
  • ASP.NET File Upload to Server using FileUpload…
  • Has Instagram Blocked your Login for no Reasons? -…
  • How to Add Share button in WordPress blog?
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

7 Things you Should not do with Ebook Writing Service
7 Things you Should not do with Ebook Writing Service
ebook writing services have the potential to change the course of your business. Writing an ebook is a terrific place to start whether you want...
Reasons Why your Social Media Marketing Campaign may Fail?
Reasons Why your Social Media Campaign may Fail?
We have all seen social media campaigns bowing out after a launch. If you do not want that to happen to your social media campaign,...
How Do I fetch the Email Ids of Clients from various Countries?
How Do I fetch the Email Ids of Clients from various Countries?
According to Google research, there are more than 7.8 billion people and 195 countries in the world. There are more than 4.1 billion email users...
How Can I fetch Phone Numbers from 1000s of Websites?
How Can I fetch Phone Numbers from 1000’s of Websites?
Websites are the best medium all over the world to connect with business owners of different industries and countries and the best source to collect...
How a Blog Can Help Create Brand Personality?
How your Blog Can help you to Create Brand Personality?
Businesses operate in a changing environment of technology and consumer demands. It is becoming essential for brands to establish a strong web presence to engage...
Which is the top Social Media Platform for Lead Generation?
Which is the top Social Media Platform for Lead Generation?
There are plenty of social media platforms you can use to generate leads from Facebook, Twitter. YouTube and Instagram just to name a few and...
4 ways Learning Management System Can Transform your Business
4 ways Learning Management System Can Transform your Business
Skilled employees are the asset of any business. And employee training has always played a significant role in imparting experience and skill to employees with...
Marketing Strategies including Content Marketing to Dynamic Pricing
Marketing Strategies including Content Marketing to Dynamic Pricing
E-commerce businesses are passing an adequate time due to the respective resources and development of the positive environment. Also, having the healthy rise of e-commerce...
Why you Should Consider Hiring an Advertising Agency for your Business?
Why you Should Consider Hiring an Advertising Agency for your Business?
Conducting business in Dubai has grown extremely competitive in recent years, and a smart advertising strategy is required to provide your products and services with...
Is there any Email Extractor to find Emails from Websites?
Is there any Email Extractor to find Emails from Websites?
Websites are the best medium all over the world to connect with business owners of different industries and the best source to collect data for...

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