Skip to content
Snippets Groups Projects

Handle unwanted symbols in login username

Closed Magnus Giesbert requested to merge magnus/website:LoginName into master
1 file
+ 5
3
Compare changes
  • Side-by-side
  • Inline
+ 5
3
@@ -7,8 +7,9 @@ if 'LDAP_HOST' in config:
@@ -7,8 +7,9 @@ if 'LDAP_HOST' in config:
import ldap3
import ldap3
def ldapauth(user, password): # pylint: disable=function-redefined
def ldapauth(user, password): # pylint: disable=function-redefined
user = LDAP_USERRE.sub(r'', user.lower())
if(LDAP_USERRE.search(user)):
try:
return {}, []
 
try:
server = ldap3.Server(config['LDAP_HOST'], port=config['LDAP_PORT'], use_ssl=True)
server = ldap3.Server(config['LDAP_HOST'], port=config['LDAP_PORT'], use_ssl=True)
conn = ldap3.Connection(server, 'fsmpi\\%s'%user, password, auto_bind=True, check_names=False)
conn = ldap3.Connection(server, 'fsmpi\\%s'%user, password, auto_bind=True, check_names=False)
except (ldap3.core.exceptions.LDAPBindError, ldap3.core.exceptions.LDAPPasswordIsMandatoryError):
except (ldap3.core.exceptions.LDAPBindError, ldap3.core.exceptions.LDAPPasswordIsMandatoryError):
@@ -26,7 +27,8 @@ else:
@@ -26,7 +27,8 @@ else:
}
}
def ldapauth(user, password): # pylint: disable=function-redefined
def ldapauth(user, password): # pylint: disable=function-redefined
user = LDAP_USERRE.sub(r'', user.lower())
if(LDAP_USERRE.search(user)):
 
return {}, []
if config.get('DEBUG') and user in NOTLDAP and password == NOTLDAP[user][0]:
if config.get('DEBUG') and user in NOTLDAP and password == NOTLDAP[user][0]:
return NOTLDAP[user][2], NOTLDAP[user][1]
return NOTLDAP[user][2], NOTLDAP[user][1]
return {}, []
return {}, []
Loading