Forms Authentication Using SQL - Part 1
page 2 of 4
by Jason N. Gaylord
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 42909/ 54

Section 1: Setting up SQL
At this point, all of the necessary work has been done to establish the base of your project. Then create a table and procedure to hold and query users and passwords. For this example, I used the following:
Authentication.sql
**************************************************

1:    CREATE TABLE [dbo].[User] (
2:    username char(25),
3:    password char(25),
4:    )
5:    
6:    
7:    CREATE PROCEDURE MyAuthentication
8:    
9:    (
10:   @username Char( 25 ),
11:   @password Char( 25 )
12:   )
13:   As
14:   
15:   DECLARE @actualPassword Char( 25 )
16:   
17:   SELECT
18:   @actualPassword = Password
19:   FROM [Users]
20:   Where username = @username
21:   
22:   IF @actualPassword IS NOT NULL
23:   IF @password = @actualPassword
24:   RETURN 1
25:   ELSE
26:   RETURN -2
27:   ELSE
28:   RETURN -1
29:   GO

The table called users holds the username and passwords of visitors. The procedure called MyAuthentication is the gateway to the table users. It allows 2 parameters to be passed, username and password. The procedure then queries the table for entries where the passed username (@username) is equal to the username in the table (username). The If..Else statement works similar to any other programming if..else statement. If no results are returned from the select statement, the procedure will return a -1. If results are returned, the next If..Else statement is executed. This statement checks to see if the passed password (@password) is equal to the actual password in the table (@actualPassword). If it is, 1 is returned. Otherwise, a -2 will be returned.

View Entire Article

User Comments

Title: c# code   
Name: raj
Date: 5/25/2011 7:51:10 AM
Comment:
Hi I want the code in C#, can u please send it?
Title: login authentication in asp.net   
Name: khyati
Date: 7/13/2009 1:09:45 AM
Comment:
very good!
Title: Good stuff   
Name: jes
Date: 4/16/2007 3:31:45 AM
Comment:
I got an error in this line
intResult = myCmd.Parameters( "RETURN_VALUE" ).Value
when i converted the code to c#.error is
intResult = myCmd.Parameters( "RETURN_VALUE" ).Value

how do i solve this
Title: Nice done but...   
Name: Edgar
Date: 9/12/2006 4:25:17 PM
Comment:
I just have a little question. What if i want to know the username of the user in other wepages???.
Title: good   
Name: ANTONY LEO EDEL
Date: 3/27/2006 5:40:52 AM
Comment:
easy to understand . lot of thanks
Title: Woooow   
Name: Eryk
Date: 2/2/2006 4:50:17 PM
Comment:
Very Very Good.
Title: very good   
Name: Tuncay
Date: 1/14/2006 2:20:40 AM
Comment:
thanks, this tutorial is very good.
Title: RE:   
Name: Bryan
Date: 11/15/2005 3:46:14 PM
Comment:
Convert sqlCommand2.Parameters["RETURN_VALUE"].Value to a integer
Title: a question!   
Name: mohammad
Date: 11/12/2005 10:15:36 AM
Comment:
hello ,thanx for this grat code ,but i have a prob!!
i have converted this code to C# and every thing is fine exept this statment
ntResult = sqlCommand2.Parameters["RETURN_VALUE"].Value;
it say can nit implicit convert from in to object ,
so can u help me in doning it in c#?
Title: excellent   
Name: jh
Date: 10/3/2005 5:21:58 PM
Comment:
very nice work - thanks much!
Title: need an import though   
Name: jh
Date: 10/3/2005 5:14:52 PM
Comment:
it neededs this at the top of the page though:

Imports System.Web.Security
Title: Perfect   
Name: Jacques
Date: 7/29/2005 4:49:45 AM
Comment:
Thank you. Just what i needed.
Title: WellDone   
Name: Man
Date: 6/16/2005 10:29:39 PM
Comment:
This was very well done and cover a whole lit of stuff that I actually was after!

Thanks!
Title: Gant   
Name: Gant Man
Date: 5/28/2005 11:30:31 PM
Comment:
Thanks

Just what I was after
Title: Good   
Name: Majun
Date: 2/10/2005 2:56:41 AM
Comment:
Very Good.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 10/24/2014 10:45:23 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search