Skip to content

fix username/password authentication #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions django_mongodb/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.core.exceptions import ImproperlyConfigured
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.signals import connection_created
from pymongo.collection import Collection
Expand Down Expand Up @@ -161,17 +160,14 @@ def _connect(self):
self.connection = MongoClient(
host=settings_dict["HOST"] or None,
port=int(settings_dict["PORT"] or 27017),
username=settings_dict.get("USER"),
password=settings_dict.get("PASSWORD"),
**settings_dict["OPTIONS"],
)
db_name = settings_dict["NAME"]
if db_name:
self.database = self.connection[db_name]

user = settings_dict["USER"]
password = settings_dict["PASSWORD"]
if user and password and not self.database.authenticate(user, password):
raise ImproperlyConfigured("Invalid username or password.")

self.connected = True
connection_created.send(sender=self.__class__, connection=self)

Expand Down