diff --git a/lib/SimpleSAML/Auth/LDAP.php b/lib/SimpleSAML/Auth/LDAP.php
index e304c79f9eeacd8093ae22559df3a00819e48bc2..328bd6e9c990c27f66efa4537329f2753da39702 100644
--- a/lib/SimpleSAML/Auth/LDAP.php
+++ b/lib/SimpleSAML/Auth/LDAP.php
@@ -186,12 +186,12 @@ class SimpleSAML_Auth_LDAP {
 		$username = addcslashes($username, ',+"\\<>;*');
 		$password = addcslashes($password, ',+"\\<>;*');
 		
+		if (isset($config['priv_user_dn']) && !$this->bind($config['priv_user_dn'], $config['priv_user_pw']) ) {
+			throw new Exception('Could not bind with system user: ' . $config['priv_user_dn']);
+		}
 		if (isset($config['dnpattern'])) {
 			$dn = str_replace('%username%', $username, $config['dnpattern']);
 		} else {
-			if (isset($config['priv_user_dn']) && !$this->bind($config['priv_user_dn'], $config['priv_user_pw']) ) {
-				throw new Exception('Could not bind with system user: ' . $config['priv_user_dn']);
-			}
 			$dn = $this->searchfordn($config['searchbase'], $config['searchattributes'], $username);	
 		}