SQL登入預存程序代碼

來源:互聯網
上載者:User

------------------------------------------------------------------------------
--登陸預存程序
------------------------------------------------------------------------------
------@IsLogin :-1:密碼錯誤 0: 使用者名稱不存在;1:登陸成功 2:使用者凍結
Use NewsData
Go
if exists(select * from sysobjects where [name]='xp_Login' and [type]='P')
begin
 drop proc xp_Login
end
Go
create proc xp_Login
@UserID varchar(20),
@Password varchar(20),
@UserState int output,
@isLogin int output,
@LastLoginTime datetime output,
@LastLoginIP varchar(20) output,
@UserMarker int output
as
 begin
 set @isLogin=(select count(0) from TB_Users where userID = @UserID and password=@Password and UserState=1);
 if(@isLogin='1')
 begin
  begin
   declare @thisLoginIP varchar(20);
   set @thisLoginIP=@LastLoginIP;
   set @LastLoginTime =(select LastLoginTime from TB_Users where UserID=@UserID);
   set @LastLoginIP =(select LastLoginIP from TB_Users where UserID=@UserID);
   set @UserMarker = (select UserMarker from TB_Users where UserID=@UserID);
   update TB_Users set LastLoginTime =getdate(),lastLoginIP = @ThisLoginIP,@UserMarker=@UserMarker+2 where UserID = @UserID;
   select roleID from TB_Users_Roles where UserID=@UserID;
  end
 end
 else
 begin
  declare @checkState int;
  set @checkState=(select count(0) from TB_Users where userID =@UserID and UserState=1);
  if(@checkState=1)
  begin
   declare @checkPwd int;
   set @checkPwd=100;
   set @checkPwd=(select UserState from TB_Users where userID = @UserID);
   if(@checkPwd=1)
   begin
    set @isLogin=-1;
   end
   else
   begin
    set @isLogin=0;
   end
  end
  else
  begin
   declare @checkName int;
   set @checkName=(select count(0) from TB_Users where userID =@UserID)
   if(@checkName=1)
   begin
    set @isLogin=2;
   end
   else
   begin
    set @isLogin=0;
   end
  end
 end
end
GO
declare
@UserState int,
@isLogin int,
@LastLoginTime datetime,
@LastLoginIP varchar(20),
@UserMarker int
set @LastLoginIP='192.168.2.116'
set @LastLoginTime='2009-1-18'
exec xp_Login 'admin','891221',@UserState output,@isLogin output,@LastLoginTime output,@LastLoginIP output,@UserMarker output
print @isLogin
print @LastLoginTime
print @LastLoginIP

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.