--BASE64编码
CREATE FUNCTION [dbo].[FnBase64Encode](@src varchar(max))
RETURNS VARCHAR(max)
as
begin
declare @bin varbinary(max)
set @bin=Convert(varbinary(max), @src)
return cast(N'' as xml).value('xs:base64Binary(xs:hexBinary(sql:variable("@bin")))', 'varchar(max)')
end
GO
--BASE64解码
CREATE FUNCTION [dbo].[FnBase64Decode](@64 varchar(max))
RETURNs VARCHAR(max)
AS
BEGIN
declare @bin varbinary(max)
set @bin=cast(N'' as xml).value('xs:base64Binary(sql:variable("@64"))', 'varbinary(max)')
return Convert(varchar(max),@bin)
END
GO
-- 存储过程demo
ALTER PROCEDURE p_user_register (@name varchar(50),@username varchar(50), @password varchar(50),@msg varchar(255) OUTPUT)
AS
BEGIN
SELECT @msg = COUNT(*) FROM t_user u WHERE u.UserName = @username AND u.Password = @password;
IF @msg = '1' BEGIN
set @msg='username 重复,请重新注册'
return 0
END
ELSE BEGIN
INSERT INTO t_user (UserName,Password,name,roles,token)
VALUES(@username, @password,@name,'admin', dbo.FnBase64Encode(@username+@password+@name+convert(varchar(19),getdate(),120)) )
set @msg='注册成功'
return 20000
END
END
sqlserver Base64 与存储过程
最新推荐文章于 2022-09-27 10:06:51 发布