Skip to main content
Inspiring
May 11, 2009
Answered

Masking text out on sensitive data

  • May 11, 2009
  • 1 reply
  • 562 views

I have a page with a form that has logon ID's and other fields that the client wants displayed as xxxx or other characters on the edit page and the results pages. How would I do this on the edit form and on the results page?

Thanks,

Shearak

    This topic has been closed for replies.
    Correct answer craigkaminsky

    Hi,

    Without getting into issues of security, you could use a session variable to hold each 'real' (unmasked) value on the form and results page and use a regular expression to replace the characters with Xs.

    Form Page

    <cfscript>

         // store the actual values in the session scope (NOTE: session management must be enabled in your app for this to work!)

         session.logonid = query_from_db.logonid_column;

         session.other_secret_field = query_from_db.secret_field_column;

         // now, mask them for use on the form --

         // the regular expression below finds any and all alphanumeric character and replaces it with an X

         logonid_masked = ReReplaceNoCase( session.logonid, '[\w]', 'X' ,'ALL' );

         other_secret_field_masked = ReReplaceNoCase( session.other_secret_field, '[\w]', 'X', 'ALL' );

    </cfscript>

    <cfoutput>

         <input type="text" id="myfield" value="#logonid_masked#" />

         <input type="text" id="myfield2" value="#other_secret_field_masked#" />

    </cfoutput>

    You could use the same approach as above on the results page.

    Hope this helps!

    Craig

    1 reply

    craigkaminskyCorrect answer
    Inspiring
    May 12, 2009

    Hi,

    Without getting into issues of security, you could use a session variable to hold each 'real' (unmasked) value on the form and results page and use a regular expression to replace the characters with Xs.

    Form Page

    <cfscript>

         // store the actual values in the session scope (NOTE: session management must be enabled in your app for this to work!)

         session.logonid = query_from_db.logonid_column;

         session.other_secret_field = query_from_db.secret_field_column;

         // now, mask them for use on the form --

         // the regular expression below finds any and all alphanumeric character and replaces it with an X

         logonid_masked = ReReplaceNoCase( session.logonid, '[\w]', 'X' ,'ALL' );

         other_secret_field_masked = ReReplaceNoCase( session.other_secret_field, '[\w]', 'X', 'ALL' );

    </cfscript>

    <cfoutput>

         <input type="text" id="myfield" value="#logonid_masked#" />

         <input type="text" id="myfield2" value="#other_secret_field_masked#" />

    </cfoutput>

    You could use the same approach as above on the results page.

    Hope this helps!

    Craig

    shearakAuthor
    Inspiring
    May 13, 2009

    Hello Craig,

    Your method and code worked great. Thank you very much for your time and code example to go along with it.