Jump to content

Find credit card numbers stored in large body of text and replace with x's


iarp

Recommended Posts

Long story short, some people have been storing credit cards in open note areas of a program they bought. It runs off of MSSQL.

 

MSSQL has no way of finding all credit card numbers and masking them with X's. So I've resorted to using PHP.

 

The area where the CC numbers were stored are the notes area, a place they also store the order details and much more.

 

# Remove all spaces, dashes, and extra html from the note.
$note = trim(strip_tags(str_replace(array('-', ' ', 'P,UL,OL,DL,DIR,MENU,PRE{margin:0auto;}'), '', $row['notes'])));

A var_dump on $note results in

string(22) "4123123412341234
blah"

RegEx to find the cards

# RegEx check against Visa, Mastercard, Amex, 
if(preg_match('/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/i', $note)) {
$found[] = $row['recid'];
}

After the while loop, i want to see what is in $found

print_r($found);
# Results in
Notice: Undefined variable: found in ..... test.php on line #

I have tried many regex strings trying to get preg_match to work. The idea is, once the recid is found to contain a credit card number i will then loop through $found again and update each row as necessary.

 

Am i using preg_match in an incorrect way? If i edit the note in the program and remove the blah so it's just the CC number it returns positive and $found gets the recid. But as soon as anything else is entered it fails and no recid.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.