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

Updates

  • An Email Marketing Strategy that Works for B2B
    •
  • How can eCommerce Strategies improve Customer Relationships?
    •
  • What are the best Strategies for Social Media Marketing?
    •
  • Everything you Should know about Hiring an Online Printing Service
    •
  • Plagiarism Checkers are Solution for Learning in Universities
    •
  • 10 Must-Have Apps for Entrepreneurs to Stay Organized
    •
  • 4 ways Learning Management System Can Transform your Business
    •
  • Why you Should Consider Hiring an Advertising Agency for your Business?
    •
  • How to make a Simple Iphone App and upload it in the App Store?
    •
  • Data Visualization’s Positive impression on Decision Making
    •
  • Everything you need to know related to Mail Forwarding Service
    •
  • Use of Etiquette to Short Sentences your Guide to Email Writing
    •
  • Why are Content Writing Services top Trending Now?
    •
  • Useful Tips Wrap Up your Blog with an effective Conclusion
    •
  • 4 Pros and 4 Cons of hiring Technical Writing Services
    •

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 80
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 use JavaScript function with ASP.NET CustomValidator?
  • How to Design a Database? - Database Design for Beginners
  • 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

Popular Categories

  • Miscellaneous591
  • Digitalization298
  • Career Guide243
  • Indian Blog207
  • Business Book177
  • Health & Wellness165
  • Travel & Tourism132
  • Your Financial Advisor116
  • Real Estate Consulting110
  • Shopping97
  • Blogging Techniques75
  • Digital Marketing70
  • Home Remedies70
  • SEO Techniques67
  • Programming62
  • Automobiles57

i20 Sidebar Widgets

A handy Guide to Personal Loan Eligibility Criteria for top Banks in INDIA
A handy Guide to Personal Loan Eligibility Criteria for top Banks in INDIA
Whether you are a salaried employee or a part-time worker, you can find several Personal Loan offers online these days. Consequently, you can find a...
The Role of Term Insurance Calculator
The Role of Term Insurance Calculator – Know why you need One for better Finances
Term insurance is a type of life insurance that provides a death benefit to your beneficiaries if anything unexpected happens to you in between the...
Post Office Recurring Deposit why a good option for long-term Investments
Post Office Recurring Deposit why a good option for long-term Investments
Post Office Recurring Deposit Scheme launched by Indian Post Offices is a deposit scheme where customers can invest money periodically which gains interest over a...
Legal Ways to eliminate Debts - Go with a Debt Settlement Company
Legal Ways to eliminate Debts – Go with a Debt Settlement Company
Most businesses often go overboard with their debts, and they are on the brink of bankruptcy. This is when they need professional help and guidance...
Financial Strategies for better Small Business Accounting
Financial Strategies for better Small Business Accounting
Small businesses constitute a significant portion of every country’s economy. However, their sustenance depends on one critical factor- accounting services. Small business accounting helps the...
5 Steps to plan your Home Loan EMI in Advance
5 Steps to plan your Home Loan EMI in Advance
Housing loans saw a growth of 14% YoY during the 3rd quarter of 2019. These loans grew by 3.5% QoQ. The growth of home loans...
Credit Mix and How It Can Impact your Credit Score?
Credit Mix and How It Can Impact your Credit Score?
The majority of the financial institutions in the US use the FICO score or credit score to determine whether you are capable of maintaining credit....
Singapore - The Emerging favorable Investment Fund Market in ASIA
Singapore – The Emerging favorable Investment Fund Market in ASIA
Singapore is ranked among the top asset management destinations in the Asian continent having as at the close of 2015 a sun of 2.6 trillion...
Best practices for used Car Loans in Adelaide
Best practices for used Car Loans in Adelaide
Owning an automobile has become a necessity in this modern era rather than being a luxury. You will seldom come across a family that does...
During Hospitalization 8 ideas to Save Money on Medical Bills
During Hospitalization 8 ideas to Save Money on Medical Bills
Medical bills can make us sick all over again. For those that are not particularly committed to their emergency savings, being hospitalized can be a...

New Releases

The biggest Real Estate Investing Mistakes and How to Avoid them?
April 15, 2025

The biggest Real Estate Investing Mistakes and How to Avoid them?

Have you ever wondered if real estate investing is as straightforward as it sounds? Does the promise of steady rental income and rising property values…

Grow your Brand Empire with Elegant Custom Favor Boxes
April 11, 2025
Grow your Brand Empire with Elegant Custom Favor Boxes
How to Buy Facebook Likes and boost your Reach?
March 29, 2025
How to Buy Facebook Likes and boost your Reach?
Strategies for Reducing Pores - A Comprehensive Guide
March 28, 2025
Strategies for Reducing Pores – A Comprehensive Guide
The Ultimate Guide to Choosing the best Health Checkup Package for you
March 26, 2025
The Ultimate Guide to Choosing the best Health Checkup Package for you
Why my Organization or Our Products and Services need Guest Posting?
March 26, 2025
How paid Guest Posting Services helps Businesses to boost Sales?
How to use Multani Mitti? - Tips and Tricks for maximum Benefits
March 26, 2025
How to use Multani Mitti? – Tips and Tricks for maximum Benefits
Transform your Guest Room with a Multi-Functional Sofa Cum Bed
March 26, 2025
Transform your Guest Room with a Multi-Functional Sofa Cum Bed
CNC Machining in Model Making Dubai for Prototypes
March 21, 2025
CNC Machining in Model Making Dubai for Prototypes
How to Choose the Right Generator for your Home?
March 21, 2025
How to Choose the Right Generator for your Home?
How to Prepare for a Tummy Tuck in Islamabad?
March 19, 2025
How to Prepare for a Tummy Tuck in Islamabad?
Trump Towers 2 - Experience the Pinnacle of Luxury Living
March 15, 2025
Trump Towers 2 – Experience the Pinnacle of Luxury Living
Why Eye Cleaning is essential for your Health?
March 14, 2025
Why Eye Cleaning is essential for your Health?
From Local to Global - Digital Growth Strategies for Indian Brands
March 10, 2025
From Local to Global – Digital Growth Strategies for Indian Brands
Tattoo Booking App - Revolutionizing the Tattoo Industry
March 10, 2025
Tattoo Booking App – Revolutionizing the Tattoo Industry
Human Behavior in Men and Women Aged 18 to 35
March 10, 2025
Human Behavior in Men and Women Aged 18 to 35
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