Hire QA – Specialized in QA Recruitment, Technical Interviews and Testing Solutions

Why Char array is preferred over String for storing password?

Category: Java

String is immutable in java and stored in String pool. Once it’s created it stays in the pool until unless garbage collected, so even though we are done with password it’s available in memory for longer duration and there is no way to avoid it. It’s a security risk because anyone having access to memory dump can find the password as clear text.
If we use char array to store password, we can set it to blank once we are done with it. So we can control for how long it’s available in memory that avoids the security threat with String.

Leave a Reply

Your email address will not be published. Required fields are marked *