Skip to content

Conversation

@nehemiah-nf
Copy link
Contributor

@nehemiah-nf nehemiah-nf commented Jul 2, 2025

Closes #4

@nehemiah-nf nehemiah-nf linked an issue Jul 2, 2025 that may be closed by this pull request
@thirstyape thirstyape self-assigned this Jul 3, 2025
@thirstyape thirstyape requested a review from Copilot July 3, 2025 12:14
Copilot

This comment was marked as outdated.

@thirstyape
Copy link
Member

@nehemiah-nf please make changes as per the following comments by Copilot.

  • XML documentation for properties changed to public
  • Explanation here as to why the digits filter was reduced from 24 to 10
  • Update CurrentIteration logic to throw an exception when TimeInterval is less than or equal to 0 (and denote the exception in XML commenting)

@nehemiah-nf
Copy link
Contributor Author

The maximum value of binary is 0x7fffffff which is 2,147,483,647 which has only 10 digits so any modulo greater than 10 is just being redundant and not actually showing that many digits in the password. It would just be a bunch of 0s followed by the 10 digit code.

@thirstyape
Copy link
Member

The maximum value of binary is 0x7fffffff which is 2,147,483,647 which has only 10 digits so any modulo greater than 10 is just being redundant and not actually showing that many digits in the password. It would just be a bunch of 0s followed by the 10 digit code.

Nice catch. The following should resolve, please update the OTP generation to use long internally.

var offset = hash[^1] & 0xFL;

var binary =
	((hash[offset] & 0x7FL) << 24) |
	((hash[offset + 1] & 0xFFL) << 16) |
	((hash[offset + 2] & 0xFFL) << 8) |
	(hash[offset + 3] & 0xFFL);

var password = binary % (long)Math.Pow(10, digits);

@thirstyape thirstyape requested a review from Copilot July 7, 2025 12:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances the OTP service by making core parameters configurable, tightening validation, and improving numeric handling in code generation.

  • Secret length is now a public, settable property.
  • Time interval for code validity is configurable with validation.
  • Bitwise operations and digit limits updated to use long types.
Comments suppressed due to low confidence (1)

Tools/OtpService.cs:22

  • The new TimeInterval setter and its validation should have unit tests covering both valid and invalid values to prevent regressions when adjusting code validity periods.
			if (value <= 0)

@thirstyape thirstyape merged commit 909e66a into master Jul 7, 2025
4 checks passed
@thirstyape thirstyape deleted the 4-enhance-otp-codes branch July 7, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance OTP codes

2 participants