登录存储过程

CREATEPROCLogin
@userNamevarchar(20),
@passwordvarchar(20)
AS
IFNOTEXISTS(SELECT*FROMUserAccountWHEREUserName=@userName)
RETURN-1
IFNOTEXISTS(SELECT*FROMUserAccountWHEREUserName=@userNameANDpassword=@password)
RETURN1

UPDATEUserAccount
SETLoginTimes=LoginTimes+1
WHEREUserName=@userName

RETURN0

CREATE PROCEDURE Prc_Ad_Login
@AdName varchar(32),
@AdPwd nchar(32),
@Count int output,
@Err varchar(64) output
AS

if exists(select intsuid from sysuser where varsuname=@AdName)
begin
declare @suid int
declare @dteErrs datetime
declare @npwd nchar(32)
declare @Lock bit
declare @intErr int
declare @Errpart int
declare @ErrCount int
select @suid=intsuid, @dteErrs=dteErr,@intErr=intErrCount,@npwd=narsupwd,@lock=bitLock from sysuser where varsuname=@Adname
select @ErrCount=intsuerrcount,@Errpart=intsuerrminute from sysbasic
if(@npwd=@Adpwd)
begin
if(@Lock=1)
begin
select @Count=2
select @Err='你的帐户已被锁定,请联系站长!'
end
else
begin

select @Count=0
end
end
else
begin
if(@Lock=0)
begin
if(datediff(n,@dteErrs,getdate())<@Errpart)
begin
if(@intErr<@ErrCount)
begin
update sysuser set intErrCount=intErrCount+1,dteErr=getdate() where intsuid=@suid
if(@intErr=(@ErrCount-1))
begin
select @Count=4
select @Err='登录错误过多,你的帐号被系统暂时锁定!'
end
else
begin
select @Count=1
select @Err='用户名或密码错误!'
end
end
else
begin
update sysuser set dteErr=getdate() where intsuid=@suid
select @Count=3
select @Err='你的帐号在一定时间内不允许登录!'
end
end
else
begin
update sysuser set dteErr=getdate(),intErrCount=1 where intsuid=@suid
select @Count=1
select @Err='用户名或密码错误!'
end
end
end
end
else
begin
select @Count=1
select @Err='用户名或密码错误!'
end
GO

你可能感兴趣的:(存储过程)