存储过程怎么防止sql注入


存储过程防止sql注入的方法:

对特殊字符进行过滤,例如:

--Function:fn_escapecmdshellstring

--Description:Returnsanescapedversionofagivenstring

--withcarets('^')addedinfrontofallthespecial

--commandshellsymbols.

--Parameter:@command_stringnvarchar(4000)

--

CREATEFUNCTIONdbo.fn_escapecmdshellstring(

@command_stringnvarchar(4000))RETURNSnvarchar(4000)AS

BEGIN

DECLARE@escaped_command_stringnvarchar(4000),

@curr_charnvarchar(1),

@curr_char_indexint

SELECT@escaped_command_string=N'',

@curr_char=N'',

@curr_char_index=1

WHILE@curr_char_index<=LEN(@command_string)

BEGIN

SELECT@curr_char=SUBSTRING(@command_string,@curr_char_index,1)

IF@curr_charIN('%','<','>','|','&','(',')','^','"')

BEGIN

SELECT@escaped_command_string=@escaped_command_string+N'^'

END

SELECT@escaped_command_string=@escaped_command_string+@curr_char

SELECT@curr_char_index=@curr_char_index+1

END

RETURN@escaped_command_string

END


上一篇:redis如何重启指定配置文件

下一篇:建站用什么cms系统好


sql注入 存储过程
Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器