SQL logon Stored Procedure Code

Source: Internet
Author: User

------------------------------------------------------------------------------
-- Login Stored Procedure
------------------------------------------------------------------------------
------ @ Islogin:-1: Password error 0: User name does not exist; 1: Login successful 2: User frozen
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 = '2017-1-18'
Exec xp_login 'admin', '000000', @ userstate output, @ islogin output, @ lastlogintime output, @ lastloginip output, @ usermarker output
Print @ islogin
Print @ lastlogintime
Print @ lastloginip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.