Quantcast
Channel: Why is char[] preferred over String for passwords? - Stack Overflow
Viewing all articles
Browse latest Browse all 20

Answer by Aditya Rewari for Why is char[] preferred over String for passwords?

$
0
0

Case String:

    String password = "ill stay in StringPool after Death !!!";    // some long code goes    // ...Now I want to remove traces of password    password = null;    password = "";    // above attempts wil change value of password    // but the actual password can be traced from String pool through memory dump, if not garbage collected

Case CHAR ARRAY:

    char[] passArray = {'p','a','s','s','w','o','r','d'};    // some long code goes    // ...Now I want to remove traces of password    for (int i=0; i<passArray.length;i++){        passArray[i] = 'x';    }    // Now you ACTUALLY DESTROYED traces of password form memory

Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>