diff --git a/idlerpg/models.py b/idlerpg/models.py index d0ff5d6..0710a2d 100644 --- a/idlerpg/models.py +++ b/idlerpg/models.py @@ -144,6 +144,19 @@ class Character(models.Model): # character is past their old time and in the process of leveling up, calculate next based on that return Game.level_formula(self.level, self.next_level) + def check_password(self, password: str): + """Check that the provided password is correct for this character. + + Used to authenicate without logging in (yet). + + Args: + password: the password to check + Raises: + ValueError: if the password is incorrect + """ + if not check_password(password, self.password): + raise ValueError(f"incorrect password for character '{self.name}'!") + def level_up(self): """Set this character's level and next time if they meet the necessary criteria. @@ -171,8 +184,7 @@ class Character(models.Model): """ if self.status != self.CHARACTER_STATUS_OFFLINE: raise ValueError(f"character '{self.name}' can't be logged in, isn't offline!") - if not check_password(password, self.password): - raise ValueError(f"incorrect password for character '{self.name}'!") + self.check_password(password) logger.debug("logging %s in...", str(self)) # we need to apply the time lost to the next level time