473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A simpler truncation function that renders credit card numbersunreadable

Background: The Payment Card Industry (PCI) Data Security Standard
(PCI DSS) is a standard for financial institutions. It requires
sensitive information, such as credit card numbers, to be "unreadable
anywhere it is stored" using hashing, truncation or encryption.

I am looking for a simple truncation function that replaces the last
four digits in the given numeric with four characters (e.g. '*'). As
as Perl programmer (where a simple "s/.{4}$/****/" would suffice), the
resulting SQL/PL code strikes me as unnecessarily complex. Is there a
simpler way?

-- Replace last four characters in decimal number with stars.
-- E.g. 1234567890123456 -123456789012**** .
CREATE FUNCTION FUNC_MASK_LAST_4 (cardno decimal(21,0))
RETURNS CHAR(32)
NO EXTERNAL ACTION
DETERMINISTIC
RETURN SUBSTR(STRIP(CAST(cardno AS CHAR(32)), T, ' '),
32 - LENGTH(STRIP(CAST(cardno as char(32)), l,
'0')) + 1,
CAST(CEIL(LOG10(cardno)) AS INT) - 4) || '****'
@

create table largenum (lval decimal(21,0) not null)
@

insert into largenum values
(1234567890123456789),
( 123456789012345678),
( 12345678901234567),
( 1234567890123456),
( 123456789012345),
( 12345678901234),
( 1234567890123),
( 123456789012),
( 12345678901),
( 1234567890),
( 123456789),
( 12345678),
( 1234567),
( 123456),
( 12345),
( 1234)
@

select lval, FUNC_MASK_LAST_4(lval) as masked from largenum
@
LVAL MASKED
----------------------- --------------------------------
1234567890123456789. 123456789012345****
123456789012345678. 12345678901234****
12345678901234567. 1234567890123****
1234567890123456. 123456789012****
123456789012345. 12345678901****
12345678901234. 1234567890****
1234567890123. 123456789****
123456789012. 12345678****
12345678901. 1234567****
1234567890. 123456****
123456789. 12345****
12345678. 1234****
1234567. 123****
123456. 12****
12345. 1****
1234. ****

16 record(s) selected.
https://www.pcisecuritystandards.org...i_dss_v1-1.pdf

Regards,
Serman D.
--
Jun 27 '08 #1
1 1842
CREATE FUNCTION FUNC_MASK_LAST_4 (cardno decfloat(34))
RETURNS CHAR(32)
NO EXTERNAL ACTION
DETERMINISTIC
RETURN SUBSTR(TRIM(CHAR(cardno)), 1, LENGTH(TRIM(CHAR(cardno))) - 4) ||
'****'
@

Prereq DB2 9.5 (DECFLOAT)
Otherwise you coulf go to BIGINT iff you can limit yourself to 18 digits

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: sam1967 | last post by:
I know how to build forms with ASP and process user input. Now i want to take credit card payments via a form. i will then download the details and process them via our credit card machine. do...
6
by: Simon Wigzell | last post by:
My client wants to have credit card information fields on his forms for his website visitors to be able to buy his wervices by credit card. The credit card info - Brand, number and expiry date will...
5
by: Jake | last post by:
I in the process of building a web-site using .net (C#). I just finished building the shopping cart. What I need is to find examples, details, or code packages that I can include in my web-site...
9
by: nm | last post by:
Hi, I am a developer quite familiar with the C# language and .NET framework. I develop mainly data driven websites. All of our past clients have shopping cart systems developed by me in ASP.NET...
6
by: Arne | last post by:
What would be a good component for processing credit cards? (I am not using commerce server.) Would I need to encrypt the credit card column in the database?
4
by: Jerry Camel | last post by:
I'm writing and ASP.net app using vb .net. I need to interact with a credit card reader. I have one that sits inline with the keyboard. Works great, except for the fact that no matter what field...
12
by: Jerry Camel | last post by:
Not sure if this is a good place to post this... I'm writing and ASP.net app using vb .net. I need to interact with a credit card reader. I have one that sits inline with the keyboard. Works...
3
by: mikekissman | last post by:
I've built an online reservation website in ASP .NET with a SQL Server backend. It allows customers to search for available resources, than charges their credit card a fee to hold the reservation....
1
by: securedcardss | last post by:
http://card.2youtop.info secured credit card card credit instant secured card cash credit secured card
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.