sql server - Stored Procedure only authenticates first user in tblUsers -
i have stored procedure authenticates users on login page.the proc first checks if email exists in table,if doesnt exist,it gives out
select 0 emailexists
and if email exists,it goes on checking correct password , on.my entire proc given below.the problem validates first user in tblusers , shows emailexists 0 other users.why that?
alter proc spvalidateuser @emailadd nvarchar(20), @password nvarchar(20) begin set nocount on; declare @emailexists bit,@userid nvarchar(10),@lastlogin datetime,@roleid int,@accountlocked bit,@retrycount int if exists(select 1 tblallusers emailadd=@emailadd) begin select @accountlocked=islocked tblallusers emailadd=@emailadd ----if account locked------ if(@accountlocked = 1) begin select 1 accountlocked,0 authenticated,0 retryattempts,1 emailexists end else begin -----check if username , password match----- select @userid = userid, @lastlogin=lastlogin, @roleid=roleid tblallusers emailadd=@emailadd , password=@password ----if match found-------- if @userid not null begin update tblallusers set lastlogin= getdate(),retryattempts=0 userid=@userid select @userid [userid], (select role tblroles roleid=@roleid) [roles],0 accountlocked,1 authenticated,0 retryattempts,1 emailexists end else ------if match not found-------- begin select @retrycount=isnull(retryattempts,0) tblallusers emailadd=@emailadd set @retrycount=@retrycount+1 if(@retrycount<=3) begin ----if retry attempts not completed------ update tblallusers set retryattempts=@retrycount emailadd=@emailadd select 0 accountlocked,0 authenticated,@retrycount retryattempts,1 emailexists end else begin ------if retry attempts completed-------- update tblallusers set retryattempts=@retrycount,islocked=1,lockeddatetime=getdate() emailadd=@emailadd select 1 accountlocked,0 authenticated,0 retryattempts,1 emailexists end end end end else begin select 0 emailexists end end
the way can see emailexists showing 0 every email address, if statement evaluating false. means, email address being entered not exist in tblallusers.
if exists(select 1 tblallusers emailadd=@emailadd) begin ... else select 0 emailexists end
if believe not case, post table data email addresses having problems with.
Comments
Post a Comment