17.07.2015 Views

Download eBook (PDF) - Red Gate Software

Download eBook (PDF) - Red Gate Software

Download eBook (PDF) - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8 – ObfuscationDECLARE @PlainVal varchar(max);DECLARE @MaskVal varchar(max);DECLARE @MaskLen int;-- Captures the portion of @OrigVal that remains in plaintextSET @PlainVal = RIGHT(@OrigVal,@InPlain);-- Defines the length of the repeating value for the maskSET @MaskLen = (DATALENGTH(@OrigVal) - @InPlain);-- Captures the mask valueSET @MaskVal = REPLICATE(@MaskChar, @MaskLen);-- Returns the masked valueReturn @MaskVal + @PlainVal;ENDGO-- Grant permissions to user defined functionGRANT EXECUTE ON dbo.Character_MaskTO Sensitive_high, Sensitive_medium, Sensitive_low;GOListing 8-4: The Character_Mask UDF.This user defined function takes advantage of system functions such asDATALENGTH, which provides the length of a value, and REPLICATE whichis used to repeat a given character for a defined number of iterations. Both ofthese are valuable to string manipulation.NOTE:Appendix A of this book provides a syntax reference regarding these systemfunctions.To illustrate the use of this, and our previous Character_Scramble userdefined function, to present data in a masked format to the user, we will createa view in the HomeLending database, called vwLoanBorrowers, for themembers of the Sensitive_high and Sensitive_medium database roles.This view, shown in Listing 8-5, will present to the lender case numbers, usingthe Character_Mask user defined function, and the borrower names usingthe Character_Scramble user defined function.Use HomeLending;GOCREATE VIEW dbo.vwLoanBorrowers178

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!