diff --git a/python/nav/web/auth/remote_user.py b/python/nav/web/auth/remote_user.py index 83a9591bed..ba89860614 100644 --- a/python/nav/web/auth/remote_user.py +++ b/python/nav/web/auth/remote_user.py @@ -18,27 +18,13 @@ """ import logging from os.path import join +import secrets from nav.auditlog.models import LogEntry from nav.config import NAVConfigParser from nav.models.profiles import Account from nav.web.auth.utils import ACCOUNT_ID_VAR -try: - # Python 3.6+ - import secrets - - def fake_password(length): - return secrets.token_urlsafe(length) - -except ImportError: - from random import choice - import string - - def fake_password(length): - symbols = string.ascii_letters + string.punctuation + string.digits - return u"".join(choice(symbols) for i in range(length)) - __all__ = [] @@ -61,6 +47,10 @@ class RemoteUserConfigParser(NAVConfigParser): _config = RemoteUserConfigParser() +def fake_password(length): + return secrets.token_urlsafe(length) + + def authenticate(request): """Authenticate username from http header REMOTE_USER