diff --git a/html/includes/authentication/active_directory.inc.php b/html/includes/authentication/active_directory.inc.php
index e6dda6b7e0..c73da1db13 100644
--- a/html/includes/authentication/active_directory.inc.php
+++ b/html/includes/authentication/active_directory.inc.php
@@ -295,7 +295,9 @@ function get_dn($samaccountname) {
}
function get_cn($dn) {
+ dn = str_replace('\\,','~',$dn);
preg_match('/[^,]*/', $dn, $matches, PREG_OFFSET_CAPTURE, 3);
+ $matches[0][0] = str_replace('~',',',$matches[0][0]);
return $matches[0][0];
}