title: Preventing LDAP injection
body: <p>I am working on my first desktop app that queries LDAP. I'm working in C under unix and using opends, and I'm new to LDAP. After woking a while on that I noticed that the user could be able to alter the LDAP query by injecting malicious code.<br>
  I'd like to know which sanitizing techniques are known, not only for C/unix development but in more general terms, i.e., web development etc.<br>
  I thought that escaping equals and semicolons would be enough, but not sure.</p>
  
  <p>Here is a little piece of code so I can make clearer the question:</p>
  
  <pre><code> String ldapSearchQuery = "(cn=" + $userName + ")";
   System.out.println(ldapSearchQuery); 
  </code></pre>
  
  <p>Obviously I do need to sanitize $userName, as stated in this <a href="http://www.owasp.org/index.php/LDAP_injection" rel="noreferrer">OWASP ARTICLE</a></p>