--新增或修改密码
create proc modifypwd
@uid varchar(16),@pwd varchar(16)
as
declare @encode varbinary(255)
set @encode=convert(varbinary(255),pwdencrypt(@pwd))
if exists(select uid from [user] where uid=@uid)
update [user] set pwd=@encode where uid=@uid
else
insert into [user](uid,pwd) values(@uid,@encode)
go
--判断密码是否正确
create proc checkid
@uid varchar(16),@pwd varchar(16)
as
declare @encode varbinary(255)
select @encode=pwd from [user] where uid=@uid
if pwdcompare(@pwd,@encode,0)='1'
select '登录成功'
else
select '用户名或密码错'
GO
--调用过程
exec modifypwd 'admin','123456'
exec checkid 'admin','123456'
--返回随机字符串的过程
create proc randomchar
@times int,@result varchar(255) out
as
declare @k int
declare @r int
declare @i int
declare @s varchar(255)
set @i=0
set @s=''
while @i<@times
begin
set @k=rand()*61
if @k<26
set @r=@k+97
else if @k>51
set @r=@k-4
else
set @r=@k 39
set @s=@s char(@r)
set @i=@i 1
end
set @result=@s
--调用
declare @s varchar(255)
exec randomchar 20,@s out