title: How to encrypt mysql password in php (or how to defeat automated code scanner red flag)
body: <p>Management strikes again.</p>
  
  <p>How should I satisfy the code scanner that is going to read my php source and red flag my MySQL connection string?</p>
  
  <ul>
  <li>Linux Server (soon to be Sun) </li>
  <li>php 4.2 (soon to be latest version)</li>
  <li>MySQL database</li>
  <li>Servers in a DMZ outside of the firewall</li>
  <li>Read only MySQL account</li>
  <li>Not a single byte of non public information in the database</li>
  </ul>
  
  <p>I have to encrypt my MySQL password in the connection string for no reason other than it is going to be red flagged by the automatic code testing solution.  Management is enthralled with the concept of <em>Pen Testing</em> without understanding it.</p>
  
  <p>I know full well it isn't any more secure to encrypt the password in the file with all the other measures in place, but my sites will be taken down if I don't comply.  I know it hurts performance but this site isn't so popular, and isn't a huge database driven app anyway.</p>
  
  <p>My attempt:</p>
  
  <pre><code>//encrypt and decrypt are functions I stole wholesale off of the php.net manual
  ...
  $SuperSecure[0] = array(encrypt("test"), encrypt("test")); //dev
  ...
  $dbcnx = mysql_connect('localhost', decrypt($SuperSecure[0][0]), decrypt($SuperSecure[0][1]));
  </code></pre>
  
  <p>Is there a better way?  More importantly, am I missing something and this is actually necessary?</p>
  
  <p>Edit:  I can't fight national anymore.  If I ignore this directive my site comes down and losing my job over this is dumb.  I just to do this as easily (and with the least performance impact) as possible.</p>