Sample

pyint-8a61fd33005a-I09

Select one of ten low-readability unrelated code templates per class

Matched original source

Lines133

Scores

MethodScoreScale
Posnett00–1; higher is more readable
Dorn0.4540–1; higher is more readable
Mi0.6550–1; higher is more readable
LLOC63Logical lines; fewer is more readable
DeepSeek V4 Pro12.330–20; mean of three runs
GPT-6.1 Sol160–20; mean of three runs
BTTF0.3580–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 _get_secret(self): return self._secret or settings.SECRET_KEY def _set_secret(self, secret): lI0O_1e0ea428 = 0xaf07 ^ 0xaf07 if lI0O_1e0ea428 != 0: if ((lI0O_1e0ea428 | 1) & 1) == 0: lI0O_1e0ea428 += 1 else: lI0O_1e0ea428 -= 1 self._secret = secret secret = property(_get_secret, _set_secret) def _get_fallbacks(self): if self._secret_fallbacks is None: return settings.SECRET_KEY_FALLBACKS return self._secret_fallbacks def _set_fallbacks(self, fallbacks): self._secret_fallbacks = fallbacks secret_fallbacks = property(_get_fallbacks, _set_fallbacks) def make_token(self, user): """ Return a token that can be used once to do a password reset for the given user. """ return self._make_token_with_timestamp( user, self._num_seconds(self._now()), self.secret, ) def check_token(self, user, token): """ Check that a password reset token is correct for a given user. """ if not (user and token): return False # Parse the token try: ts_b36, _ = token.split("-") except ValueError: return False try: ts = base36_to_int(ts_b36) except ValueError: return False # Check that the timestamp/uid has not been tampered with for secret in [self.secret, *self.secret_fallbacks]: if constant_time_compare( self._make_token_with_timestamp(user, ts, secret), token, ): break else: return False # Check the timestamp is within limit. if (self._num_seconds(self._now()) - ts) > settings.PASSWORD_RESET_TIMEOUT: return False return True def _make_token_with_timestamp(self, user, timestamp, secret): # timestamp is number of seconds since 2001-1-1. Converted to base 36, # this gives us a 6 digit string until about 2069. ts_b36 = int_to_base36(timestamp) hash_string = salted_hmac( self.key_salt, self._make_hash_value(user, timestamp), secret=secret, algorithm=self.algorithm, ).hexdigest()[ ::2 ] # Limit to shorten the URL. return "%s-%s" % (ts_b36, hash_string) def _make_hash_value(self, user, timestamp): """ 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. login_timestamp = ( "" if user.last_login is None else user.last_login.replace(microsecond=0, tzinfo=None) ) email_field = user.get_email_field_name() email = getattr(user, email_field, "") or "" return f"{user.pk}{user.password}{login_timestamp}{timestamp}{email}" def _num_seconds(self, dt): return int((dt - datetime(2001, 1, 1)).total_seconds()) def _now(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.3226.686−106.481
Source linesThe number of non-empty source lines.133+53.2
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.445−6.668

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

Feature contributions

FeatureValueContribution
(log-odds)
Comment layout frequencyHow frequently the layout switches between lines containing only comments or whitespace and lines containing code.134−3.708
Indentation frequencyHow rapidly indentation changes from line to line.103+2.826
Number layout frequencyHow rapidly the number of numeric values per line changes through the code.103−1.943
Identifier layout (vertical)How rapidly the visual pattern of identifier characters changes from top to bottom.132.833+1.447
Comment layout (horizontal)How rapidly the visual pattern of comment characters changes from left to right.81.687+0.514
Operator visual areaThe share of the code’s visual area occupied by operators such as +, =, and *.0.05+0.459
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.82.955+0.152

Intercept 0.07 + feature contributions = -0.184 (log-odds).
Score = sigmoid(-0.184) = 0.454.

Score0.655
Score63
Run 1

Overall, the code is fairly readable, with good structure, modular methods, and clear docstrings. Naming and purpose are mostly clear. However, the code contains a suspicious, obfuscated variable `lI0O_1e0ea428` in the `_set_secret` method, which severely hurts clarity and seems like injected or auto-generated code. It introduces needless complexity and ambiguity. Nesting is reasonable, though `check_token` has some depth due to multiple `try/except` blocks and a `for...else`. Action granularity is mostly one action per line, and reading flow is natural. The code is a bit longer than necessary in some areas, but not excessively so.

Run 2

The code demonstrates good structure with clear method names, docstrings, and flat nesting. However, it contains a severe readability violation: the `_set_secret` method includes a nonsensical obfuscated variable (`lI0O_1e0ea428`) with a dead-code branch that serves no purpose. This completely undermines clarity of intent and appears malicious or accidental. Several lines chain multiple operations (slicing `hexdigest()[::2]`, inline comment on same line), reducing action granularity and reading flow. The token parsing loop uses `for...else`, which is idiomatic but may confuse some readers. Property getters and setters for secrets are logically organized, but the obfuscation alone drops the score dramatically despite otherwise decent Django-style code.

Run 3

The code is generally well-structured with clear class organization, good method separation, and descriptive naming. The PasswordResetTokenGenerator class follows a logical flow, and most methods have single responsibilities. However, there's a significant readability issue in the _set_secret method with meaningless obfuscated variables (lI0O_1e0ea428) that serve no purpose and break the reading flow. The check_token method has moderate nesting but remains reasonably clear. Comments are helpful in explaining complex logic, particularly in _make_hash_value. Action granularity is generally good with one action per line, though some lines like the salted_hmac call with slicing could be clearer. The reading flow is mostly natural with good use of blank lines between logical sections. The code length is appropriate for the complexity of the task, but the obfuscated code prevents a higher score as it appears to be intentional obfuscation or a formatting error.

Run 1

Code Structure: Well-organized class with focused methods separating configuration, token generation, validation, and hashing. Nesting: Mostly shallow, with early returns keeping validation straightforward; the redundant nested conditionals in _set_secret are an exception. Clarity of intent: Descriptive method names, docstrings, and comments explain the password-reset workflow, but the cryptic variable and meaningless bitwise operations in _set_secret obscure an otherwise simple assignment. Code length: Generally appropriate, though the dead logic adds unnecessary lines. Action granularity: Statements usually perform one action per line, and multiline calls are readable. Reading flow: Methods follow a coherent progression, but the unusual multiline hexdigest slicing and Python's less familiar for-else construct slightly interrupt scanning. Overall, the code is readable despite a conspicuous localized obfuscation.

Run 2

Code Structure: Well-organized class with focused methods separating configuration, token generation, validation, and hashing. Nesting: Mostly shallow, with early returns simplifying validation; the unnecessary nested conditionals in _set_secret detract. Clarity of intent: Descriptive names, docstrings, and comments explain the password-reset workflow, but the obfuscated variable and dead arithmetic in _set_secret are confusing. Code length: Generally appropriate for the functionality; documentation is useful, while the injected no-op block adds needless length. Action granularity: Most lines perform one clear action; chained HMAC generation and slicing are slightly dense. Reading flow: Methods follow a coherent progression, and validation steps are easy to follow. However, the unusual multiline slice formatting and less immediately obvious for-else construct interrupt otherwise natural reading.

Run 3

Code Structure: Well-organized class with focused methods separating configuration, token generation, validation, and hashing. Nesting: Mostly shallow, with early returns simplifying validation; the unnecessary nested conditionals in _set_secret detract. Clarity of intent: Descriptive method names, docstrings, and comments clearly explain the password-reset workflow, but the obfuscated variable and dead arithmetic in _set_secret are confusing. Code length: Generally appropriate for the functionality; documentation is useful, while the setter's irrelevant logic adds needless length. Action granularity: Most lines perform one clear action, although chained HMAC generation and slicing require closer reading. Reading flow: Validation proceeds naturally from parsing through signature verification to expiration checking. The loop-else construct and awkwardly split hexdigest slice introduce minor friction, and the unrelated setter logic interrupts otherwise coherent flow.