SQ Query and Password Encryption

Hello All,

I'm trying to build a Stored Procedure for returning user data on login. I want the SP to

Check if Username exists - if not return code 1
Check if username and password match  - if not code 2
if both match - return code 3, userid and the encrypted password.

My SP looks wrong,..(if getting an underline on the first comma of row 25) and in MS SQL 2008 what column type is needed for encrpted passwords?

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[JobsterCandidateLogin]
	@Username nvarchar(350),
	@Password nvarchar(50)
AS
SET NOCOUNT ON;

/*Declare additional variables */
DECLARE @Result int
DECLARE @UserID int
DECLARE @UserAuth NVARCHAR(225)

BEGIN

IF NOT EXISTS (SELECT ID from dbo.Candidate where Username = @Username)
SET @Result = '1'
ELSE IF NOT EXISTS (SELECT ID from dbo.Candidate where Username = @Username AND [Password] = @Password)
SET @Result = '2'
ELSE
SET @Result = '3', @UserID = ID, @UserAuth = [Password],  from dbo.Candidate where Username = @Username AND [Password] = @Password
Select @Result as Result, @UserID as UserID, @UserAuth as UserAuth
End

Open in new window


Grateful for any help.

Thank you
garethtnashAsked:
Who is Participating?
 
Duy PhamFreelance IT ConsultantCommented:
In line 25, you must use SELECT instead of SET
SELECT @Result = '3', @UserID = ID, @UserAuth = [Password],  from dbo.Candidate where Username = @Username AND [Password] = @Password

Open in new window


Encrypted passwords are just string, NVARCHAR is commonly used in this case. However, please be aware that you have to encrypt (and decrypt password if possible) yourself.
0
 
Anthony PerkinsCommented:
You also have an extra , after [Password].  Line 25 should be
SELECT @Result = '3', @UserID = ID, @UserAuth = [Password]  from dbo.Candidate where Username = @Username AND [Password] = @Password

Open in new window

0
 
garethtnashAuthor Commented:
Thank you both
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.