Wednesday, October 27, 2010

Authenticate Member SP

ALTER PROCEDURE [The].[prc_MemberAuthenticate]
@chvEmail varchar(128),
@chvnPassword nvarchar(100),
@ReturnCode int OUT
AS
DECLARE @chvnMemberPassword NVARCHAR(128),
@chvMemberNo varchar (9),
@chvEmailDB varchar(128),
@IsPaid bit


SET @chvMemberNo = ''
SET @IsPaid = 0

BEGIN
SELECT @IsPaid = IsPaid,@chvMemberNo = MemberID, @chvnMemberPassword = [Password], @chvEmailDB = Email
FROM The.Memberships WHERE Email = @chvEmail and IsPaid = 1

IF (@IsPaid = 0)
BEGIN
SET @returnCode = -3 --Unpaid
END
ELSE IF (@chvEmailDB is null OR @chvEmailDB = '')
BEGIN
SET @returnCode = -1 --Wrong UserName
END
ELSE IF (@chvnPassword <> @chvnMemberPassword)
BEGIN
SET @returnCode = -2 --Wrong Password
END
--ELSE IF (@var_Status=0)
-- BEGIN
-- SET @returnCode = -3 -- Not active
-- END
ELSE
BEGIN
SET @returnCode = 1 -- Login successfully
END

IF (@returnCode = 1)
BEGIN
SELECT MemberID,MemberNo, (FirstName + ' ' + LastName) as Name
FROM The.Memberships
WHERE Email = @chvEmail
END
END

No comments: