Better way to escape the ldap filter and username

Re-did this PR so it should merge cleanly.