MDL-48255 auth_ldap: make ldap cookie check more robust

Thanks to Baptiste Desprez for spotting this and provide a solution.