Skip to content
Open
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
11 changes: 1 addition & 10 deletions server/auth/local/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def __init__(self) -> None:
self.totp_key = get_env("FLATNOTES_TOTP_KEY", mandatory=True)
self.totp_key = b32encode(self.totp_key.encode("utf-8"))
self.totp = TOTP(self.totp_key)
self.last_used_totp = None
self._display_totp_enrolment()

def login(self, data: Login) -> Token:
Expand All @@ -49,8 +48,7 @@ def login(self, data: Login) -> Token:
# Check Password & TOTP
expected_password = self.password
if self.is_totp_enabled:
current_totp = self.totp.now()
expected_password += current_totp
expected_password += self.totp.now()
password_correct = secrets.compare_digest(
expected_password, data.password
)
Expand All @@ -59,15 +57,8 @@ def login(self, data: Login) -> Token:
if not (
username_correct
and password_correct
# Prevent TOTP from being reused
and (
self.is_totp_enabled is False
or current_totp != self.last_used_totp
)
):
raise ValueError("Incorrect login credentials.")
if self.is_totp_enabled:
self.last_used_totp = current_totp

# Create Token
access_token = self._create_access_token(data={"sub": self.username})
Expand Down