从 Coldfusion 的备忘录字段中替换信用卡号

Replacing credit card numbers from a memo field in Coldfusion

我有一个来自备注字段的字符串,上面有一些信用卡,我想屏蔽数字以仅显示最后 4 位数字。示例:

<cfset str = "Her card no. is 1234567890123456 which is a bogus number.">

如何使 str 的值读取:

Her card no. is ************3456 which is a bogus number.

这样的事情怎么样。您可能需要更改正则表达式数字匹配最大值,具体取决于您的信用卡号码范围:

更新 02.07.18

<cfset str = "Her card no. is 1234567890123456 which is a bogus number.">
<cfset maskall = true>

<cfset regex = ".*[\s]+([0-9]{8,19})[\s]+.*">

<cfset ccNumberProtected = "">

<cfif REFindNoCase(regex,str)>
  <cfset ccNumber = REReplaceNoCase(str,regex,"")>
  <cfif maskall>
    <cfset ccNumberProtected = RepeatString("*",Len(ccNumber))>
  <cfelse>
    <cfset ccNumberProtected = RepeatString("*",Len(ccNumber) - 4) & Right(ccNumber,4)>
  </cfif>
</cfif>

<cfif Len(Trim(ccNumberProtected))>
  <cfset str = "Her card no. is " & ccNumberProtected & " which is a bogus number.">
<cfelse>
  <cfset str = "Card number could not be displayed for security reasons">
</cfif>

使用以下内容获取您在问题中提出的数字。这甚至会动态改变数字。

<cfset str="Her card no. is 1234567890123456  which is a bogus number.">
<cfset num=listGetAt(str,5,' ')>
<cfset card=right(num,4)>
<cfset card=listInsertAt(card,1,'************')>
<cfset card=listChangeDelims(card,'')>
<cfset card=replaceList(str,num,card)>
<cfdump var="#card#" />

How can I make the value of the str to read:

Her card no. is ************3456 which is a bogus number.

简单:

停止在文本字段中保存信用卡号!

这是 PCI 合规性噩梦。这种做法可能会导致您的公司在您接受审计时不再处理在线支付。

您需要尽快停止这种情况并启动一个项目,以像这样从所有以前的整体中清除未加密的 CC 号码。如果您将他们的 CC 号码保存在系统的其他位置,则只需保存最后 4 位数字。然后您可以在消息中引用该字段。

当评论/备忘录保存在任何地方时,您需要清除与抄送号码、银行 routing/account 和社会安全号码匹配的号码模式的数据。

这看起来像是生产支持票中的内容,所以我敦促您尽快改变这种做法。如果他们存档的 CC 是假的,那么就在你的备忘录中这样说:

The card number currently on file is invalid.

我最近想到了一个不同的解决方案,后来在搜索其他解决方案时发现了这个问题。我最初的正则表达式没有检测到所有信用卡格式(space、破折号、没有 spaces)并且错误地屏蔽了 Instagram 和 GooglePlus URL,但是这个很好用并且使用 Luhn 算法只修改实际信用卡价值。

查看博客条目,了解使用 Adob​​e ColdFusion 或 Lucee 的实时可编辑演示。 https://gamesover2600.tumblr.com/post/176823552659/mask-credit-card-numbers-using-coldfusion

<cfscript>
function maskCC(textFragment){
    var response = Javacast("string", arguments.textFragment);
    var temp = {};
    temp.TestCCs = reMatch("\b(?:\d[ -]*?){13,16}\b", response);
    if (arrayLen(temp.TestCCs)){
        for (temp.thisCC in temp.TestCCs) {
            temp.cleanNum = reReplace(temp.thisCC,"[^[:digit:]]","","all");
            if( isValid("creditcard", Temp.cleanNum )){
                response = Replace(response, temp.thisCC, "************" & Right(Temp.cleanNum,4), "all");
            }
        }
    }
    return response;
}
</cfscript>

<CFOUTPUT>
<pre>
#maskCC('4444 3333 2222 1111')# (with spaces)
#maskCC('4444-3333-2222-1111')# (with dashes)
#maskCC('4444333322221111')# (no separators)
#maskCC('1234567890123456')# (not a CC)

GENERIC TEXT FROM TEXTAREA FORM FIELD:
#maskCC('Here is my unsecure CCNum: 4444333322221111.
My transaction ID IS: 4567123498765283. Please refund.')#
</pre>
</CFOUTPUT>