954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

store procedure in sql server

i write the procedure for login in this user can give username or emailid for the login. this is my code.... please check is there any change is required for this

ALTER procedure [dbo].[users_login] (@username varchar(50),@password varchar(50),
  @emailid varchar(50),@ret int output)
as
  begin
       select username,password,emailid from users where( username=@username or
        emailid=@emailid) and [password]=@password
       if(@@rowcount >0)
          begin
                set @ret=1
          end
       else
           begin
               set @ret=0
            end
  end
sasidhars
Newbie Poster
3 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

I wouldn't rely on @@rowCount. Plus, logic for user login / email looks "liberal", one can enter valid login and invalid email. My preferred logic would be:

ALTER procedure [dbo].[users_login] (@username varchar(50),@password varchar(50),
@emailid varchar(50),@ret int output)
as
begin

set @ret=0
if @emailid <> '' or @username <> ''
begin
  select @ret=1, username,password,emailid from users 
   where ( ( username=@username and @username <> '' )or 
 ( emailid= @emailid and @emailid <> '')) and [password]=@password
end

end


Please close thread once you get good enough help.

padtes
Junior Poster in Training
86 posts since Aug 2009
Reputation Points: 53
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: