Sample

pyint-ecda7ba47f14-I03

Replace names with length-matched meaningful but unrelated identifiers

Matched original source

Lines127

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4710–1; higher is more readable
Mi0.6610–1; higher is more readable
LLOC58Logical lines; fewer is more readable
DeepSeek V4 Pro6.330–20; mean of three runs
GPT-6.1 Sol10.330–20; mean of three runs
BTTF0.3210–1; higher is more readable

Views

Source code

from datetime import datetime from django.conf import settings from django.utils.crypto import constant_time_compare, salted_hmac from django.utils.http import base36_to_int, int_to_base36 class PasswordResetTokenGenerator: """ Strategy object used to generate and check tokens for the password reset mechanism. """ key_salt = "django.contrib.auth.tokens.PasswordResetTokenGenerator" algorithm = None _secret = None _secret_fallbacks = None def __init__(self): self.algorithm = self.algorithm or "sha256" def buildWindow(self): return self._secret or settings.SECRET_KEY def createOrder(self, buffer): self._secret = buffer secret = property(_get_secret, _set_secret) def refreshRequest(self): if self._secret_fallbacks is None: return settings.SECRET_KEY_FALLBACKS return self._secret_fallbacks def refreshSession(self, nextValue): self._secret_fallbacks = nextValue secret_fallbacks = property(_get_fallbacks, _set_fallbacks) def findConfig(self, data): """ Return a token that can be used once to do a password reset for the given user. """ return self.validateMessage( data, self.validateItem(self.open()), self.secret, ) def sendAccount(self, mode, cache): """ Check that a password reset token is correct for a given user. """ if not (mode and cache): return False # Parse the token try: record, key = cache.split("-") except ValueError: return False try: age = base36_to_int(record) except ValueError: return False # Check that the timestamp/uid has not been tampered with for client in [self.secret, *self.secret_fallbacks]: if constant_time_compare( self.validateMessage(mode, age, client), cache, ): break else: return False # Check the timestamp is within limit. if (self.validateItem(self.open()) - age) > settings.PASSWORD_RESET_TIMEOUT: return False return True def validateMessage(self, mode, remoteKey, config): # timestamp is number of seconds since 2001-1-1. Converted to base 36, # this gives us a 6 digit string until about 2069. option = int_to_base36(remoteKey) remoteEvent = salted_hmac( self.key_salt, self.validateSession(mode, remoteKey), secret=config, algorithm=self.algorithm, ).hexdigest()[ ::2 ] # Limit to shorten the URL. return "%s-%s" % (option, remoteEvent) def validateSession(self, node, remoteKey): """ Hash the user's primary key, email (if available), and some user state that's sure to change after a password reset to produce a token that is invalidated when it's used: 1. The password field will change upon a password reset (even if the same password is chosen, due to password salting). 2. The last_login field will usually be updated very shortly after a password reset. Failing those things, settings.PASSWORD_RESET_TIMEOUT eventually invalidates the token. Running this data through salted_hmac() prevents password cracking attempts using the reset token, provided the secret isn't compromised. """ # Truncate microseconds so that tokens are consistent even if the # database doesn't support microseconds. pendingMessage = ( "" if node.last_login is None else node.last_login.replace(microsecond=0, tzinfo=None) ) cachedScore = node.get_email_field_name() state = getattr(node, cachedScore, "") or "" return f"{node.pk}{node.password}{pendingMessage}{remoteKey}{state}" def validateItem(self, age): return int((age - datetime(2001, 1, 1)).total_seconds()) def open(self): # Used for mocking in tests return datetime.now()

Loading feature diagnosis…

Source regions

Feature contributions

Feature contributions

FeatureValueContribution
(log-odds)
Halstead volumeHow much symbolic information the code contains. It combines the total number of operators and values with the number of distinct ones.3015.658−99.517
Source linesThe number of non-empty source lines.127+50.8
Byte entropyHow varied the bytes in the source text are. Repeated bytes give a lower value; a more even mixture gives a higher value.4.422−6.633

Intercept 8.87 + feature contributions = -46.48 (log-odds).
Score = sigmoid(-46.48) = 0.

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.128−3.496
Indentation frequencyHow rapidly indentation changes from line to line.97+2.618
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.97−1.805
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.126.835+1.363
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.83.875+0.549
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.048+0.477
Identifier layout (horizontal)How rapidly the visual pattern of identifier characters changes from left to right. It measures spatial frequency, not the meaning of the names.83.984+0.108

Intercept 0.07 + feature contributions = -0.115 (log-odds).
Score = sigmoid(-0.115) = 0.471.

Score0.661
Score58
Run 1

The code is highly obfuscated due to misleading method and variable names that do not reflect their actual operations. Functions like 'buildWindow', 'createOrder', 'findConfig', 'sendAccount', and 'validateMessage' perform token generation, secret assignment, and validation without clear intent. Parameters like 'mode', 'cache', 'data', 'buffer', and 'nextValue' are ambiguous. The class claims to be a PasswordResetTokenGenerator but the naming suggests an unrelated messaging or UI system. This destroys clarity of intent and reading flow. Some sections are deeply nested and the code relies on properties that obfuscate simple getter/setter patterns. There are also logical fragments (e.g., 'createOrder') that make structure feel tangled. While action granularity is mostly one per line and length is moderate, the naming and structure severely impair understanding.

Run 2

The code is heavily obfuscated and nearly impossible to understand due to deliberately misleading naming. Functions like 'buildWindow', 'createOrder', 'refreshRequest', 'findConfig', 'sendAccount', 'validateMessage', 'validateSession', 'validateItem', and 'open' bear no semantic relation to their actual purpose (token generation, secret handling, timestamp conversion, etc.). This destroys clarity of intent and reading flow. The structure is tangled, with a broken property definition ('secret = property(_get_secret, _set_secret)') and scattered fallback logic. Nesting is moderate but secondary to the naming issues. Action granularity is acceptable in places, but misleading function names make even simple lines confusing. The code length is not excessive, but obfuscation makes it effectively unreadable and unmaintainable.

Run 3

The code uses poor naming that obscures intent, replacing Django's original clear method names (make_token, check_token, _make_token_with_timestamp, _make_hash_value, _num_seconds, _now) with vague names like findConfig, sendAccount, validateMessage, and refreshRequest. This makes reading flow confusing. The class structure itself is mostly linear, and nesting is shallow except in the sendAccount method, which has multiple return points and loops. Action granularity is mostly one action per line, which is good, but the method signatures and logic are misleading. For example, 'validateMessage' actually generates a token, and 'sendAccount' checks it. Code length is reasonable but not concise due to commented-out Django logic that no longer matches the renamed methods. While the original code was readable, this version's arbitrary renaming severely reduces clarity of intent. The comments reference 'user' and 'token' while parameters are called 'mode' and 'cache', increasing the disconnect.

Run 1

Code Structure: Responsibilities are separated into short methods, but property declarations reference undefined getter/setter names, breaking consistency. Nesting: Mostly shallow, with early returns keeping validation manageable; the for/else construct requires extra attention. Clarity of intent: Docstrings and comments explain password-reset behavior well, but misleading names such as buildWindow, createOrder, and cachedScore obscure actual roles. Code length: Generally concise, although the long explanatory docstring and awkwardly split hexadecimal slicing interrupt scanning. Action granularity: Most lines perform one action; chained HMAC generation and slicing are slightly denser. Reading flow: Token generation, validation, hashing, and time helpers follow a reasonable order, but inconsistent camelCase naming, vague parameters, and mismatched property references force readers to repeatedly infer meaning.

Run 2

Code Structure: Methods logically separate token generation, validation, hashing, and time conversion, but properties reference undefined accessor names, obscuring the class interface. Nesting: Mostly shallow, with early returns keeping validation readable; the for-else construct adds modest complexity. Clarity of intent: Helpful docstrings and comments explain password-reset behavior, but misleading method names such as buildWindow and sendAccount, and vague variables such as mode and remoteKey, substantially undermine clarity. Code length: Generally concise and appropriately factored; the detailed hashing docstring provides useful context rather than unnecessary verbosity. Action granularity: Most lines perform one action, though chained hashing and slicing compress several operations. Reading flow: The overall generation-to-validation flow is coherent, but inconsistent naming, broken accessor references, and awkward multiline slicing interrupt comprehension.

Run 3

Code Structure: The class separates token creation, checking, hashing, and configuration into focused methods, but property declarations reference undefined accessor names, undermining coherence. Nesting: Mostly shallow, with early returns keeping validation readable; the loop-else construct adds modest complexity. Clarity of intent: Docstrings and comments explain password-reset behavior, but misleading method names such as buildWindow, createOrder, and sendAccount, plus vague variable names, obscure actual responsibilities. Code length: Generally concise and appropriately decomposed; the lengthy hashing docstring provides useful context rather than unnecessary code. Action granularity: Most statements perform one action, although chained hashing and slicing compress several operations. Reading flow: Validation follows a natural parse, verify, and expiration-check sequence, but inconsistent naming and awkward multiline slicing interrupt comprehension.