aspose file tools*
The moose likes Other Open Source Projects and the fly likes Masking Password in log file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Masking Password in log file" Watch "Masking Password in log file" New topic
Author

Masking Password in log file

Nila Shah
Greenhorn

Joined: Jun 04, 2007
Posts: 7
Hi,

I need several field in the logfile to be masked.
Like the creditcard info or password.
Do we have any direct way to do it ?
Or any code piece we have to write in for logg fields to mask those Credit card info so that those will be appreaed mask in log file.
Example:
CreditcardNo:411111111111 should apprear in log file as *********1111
password assword123 should apprear in log as ***********
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

What are you using for logging? Any frameworks? Are these logs generated from a java application?


[My Blog] [JavaRanch Journal]
Nila Shah
Greenhorn

Joined: Jun 04, 2007
Posts: 7
Yes. This application is a struts base application and log4j is used for logging.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

If all that you want is to mask those fields from your logs, you wont have to do much. If your current code is:



Just change it to



Is this what you are looking for? Or have i understood your question wrong?
Nila Shah
Greenhorn

Joined: Jun 04, 2007
Posts: 7
Thanks Jaikiran for your reply.
But My issue is it should dynamically do that masking.
For and example if the creditcard number is 123456789 then it should show in log file as *****6789.

So I can't replace with only "*************"
steve souza
Ranch Hand

Joined: Jun 26, 2002
Posts: 861
If you would like a more general solution I have a class that takes any String that is surrounded by quotes or double quotes, and replaces it with a '?'. You could do something similar. Create your own logger class and call log4j from it



Another option would be to create a log4j appender or Layout Conversion that does the same. The advantage of this approach is that you wouldn't have to change your code that calls logger. If you are interested in such code i can post it.
[ June 04, 2007: Message edited by: steve souza ]

http://www.jamonapi.com/ - a fast, free open source performance tuning api.
JavaRanch Performance FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Masking Password in log file