Click here to Skip to main content
15,891,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am writing a prog on store procedure and i am checking the username password with stored procedure.but unable to get the required stored procedure.how to write the sp.
Posted

How you do that will depend on what you do with your passwords: If you store them as plain text (very bad) then it is a simple comparison; if you store them as encrypted binary info (strongly recommended) then it is more complex.

There is some general advice of passwords here: Password Storage: How to do it.[^]
 
Share this answer
 
As far as I understood your question you want stored procedure to verify username and password

Refer this:

http://forums.asp.net/t/1453256.aspx/1[^]
 
Share this answer
 
v2
In addition to other solutions remember to store your passwords encrypted, Its not necessary but it will bring you more security.
Here is a simple example of users table :

SQL
CREATE TABLE [dbo].[User](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [UserName] [varchar](50) NOT NULL,
    [Pass] [image] NULL,
    [FirstName] [varchar](50) NULL,
    [LastName] [varchar](50) NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED
(
    [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


And the login procedure :
SQL
CREATE PROCEDURE sp_LoginUser
@uname as varchar(100),
@password as varchar(100)
AS
SELECT     *
FROM         [User] 
WHERE		(UserName=@uname ) and (convert(varbinary, Pass) = HASHBYTES('MD5', @password))


Check the returned rows after calling this procedure if there is no result so login is failed.
Also use HASHBYTES when inserting new users or editing their passwords.

To get the HASHBYTES output in your .NET code use this snippet :

C#
public static byte[] HashString(string input)
{
    System.Security.Cryptography.MD5CryptoServiceProvider csp = new System.Security.Cryptography.MD5CryptoServiceProvider();
    return csp.ComputeHash(System.Text.Encoding.ASCII.GetBytes(input));      
}



Hope it helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900