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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.