转:防止SQL注入性字符的判断函数

CREATE FUNCTION [dbo].[fn_CheckSQLInjection] ( @Col nvarchar(4000) ) RETURNS BIT --如果存在可能的注入字符返回true,反之返回false
AS

BEGIN

DECLARE @result bit;  
IF       

  UPPER(@Col) LIKE UPPER(N'%0x%')

   OR UPPER(@Col) LIKE UPPER(N'%;%')

   OR UPPER(@Col) LIKE UPPER(N'%''%')

   OR UPPER(@Col) LIKE UPPER(N'%--%')

   OR UPPER(@Col) LIKE UPPER(N'%/*%*/%')

   OR UPPER(@Col) LIKE UPPER(N'%EXEC%')

   OR UPPER(@Col) LIKE UPPER(N'%xp_%')

   OR UPPER(@Col) LIKE UPPER(N'%sp_%')

   OR UPPER(@Col) LIKE UPPER(N'%SELECT%')

   OR UPPER(@Col) LIKE UPPER(N'%INSERT%')

   OR UPPER(@Col) LIKE UPPER(N'%UPDATE%')

   OR UPPER(@Col) LIKE UPPER(N'%DELETE%')

   OR UPPER(@Col) LIKE UPPER(N'%TRUNCATE%')

   OR UPPER(@Col) LIKE UPPER(N'%CREATE%')

   OR UPPER(@Col) LIKE UPPER(N'%ALTER%')

   OR UPPER(@Col) LIKE UPPER(N'%DROP%')

   SET @result=1 

ELSE   SET @result=0 

return @result

END

GO

注:转自这里   http://www.cnblogs.com/Joe-T/archive/2011/11/28/2266280.html

posted on 2011-12-01 11:56  玄德  阅读(185)  评论(0)    收藏  举报