Skip to content

Commit

Permalink
Accommodate tenant architecture by checking for a SiteSettings model …
Browse files Browse the repository at this point in the history
…to see if previous_password_count has been set
  • Loading branch information
rsmith0717 committed Dec 8, 2021
1 parent 8f2d4c5 commit e4bdadd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ History
++++++++++++++++++

* First release on PyPI.


1.0.1 (2021-12-08)
++++++++++++++++++

* Accommodate tenant architecture by checking for a SiteSettings model to see if previous_password_count has been set.
* Second release on PyPI.
2 changes: 1 addition & 1 deletion django_password_history/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = '1.0.1'
20 changes: 15 additions & 5 deletions django_password_history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ class UserPasswordHistory(models.Model):
password_5 = models.CharField(blank=True, null=True, max_length=128)
updated_at = models.DateTimeField(auto_now=True)

def password_is_used(self, password):
if settings.PREVIOUS_PASSWORD_COUNT:
previous_passwords_count = settings.PREVIOUS_PASSWORD_COUNT
def password_is_used(self, password, site_id=1):
previous_passwords_count = 5
SiteSettings = None

use_site_setting_password_history = getattr(settings,"USE_SITE_SETTINGS_PASSWORD_HISTORY",False)

try:
SiteSettings = apps.get_model("setup","SiteSettings")
except:
SiteSettings = None

if use_site_setting_password_history and SiteSettings:
previous_passwords_count = SiteSettings.objects.get(id=site_id).previous_password_count
else:
previous_passwords_count = 5
previous_passwords_count = getattr(settings,"PREVIOUS_PASSWORD_COUNT", 5)

if previous_passwords_count:
for x in range(1, min(previous_passwords_count, 5) + 1):
Expand All @@ -33,4 +43,4 @@ def store_password(self):
self.password_3 = self.password_2
self.password_2 = self.password_1
self.password_1 = self.user.password
self.save()
self.save()

0 comments on commit e4bdadd

Please sign in to comment.