[GH-ISSUE #24] Generated secret key isn't cryptographically secure #11

Closed
opened 2026-02-25 20:32:11 +03:00 by kerem · 4 comments
Owner

Originally created by @aik099 on GitHub (Mar 11, 2016).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/24

The Google2FA::generateSecretKey method internally uses Google2FA::getRandomNumber, which uses mt_rand function. According to its documentation (see http://php.net/mt_rand) it should not be used in security-related contexts.

Since current usage exactly qualifies as security related context I'm proposing to:

  1. use https://packagist.org/packages/paragonie/random_compat package to get random_int function, that was added only in PHP 7
  2. use random_int instead of mt_rand

If you're interested I can send a PR.

Originally created by @aik099 on GitHub (Mar 11, 2016). Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/24 The `Google2FA::generateSecretKey` method internally uses `Google2FA::getRandomNumber`, which uses `mt_rand` function. According to its documentation (see http://php.net/mt_rand) it should not be used in security-related contexts. Since current usage exactly qualifies as security related context I'm proposing to: 1. use https://packagist.org/packages/paragonie/random_compat package to get `random_int` function, that was added only in PHP 7 2. use `random_int` instead of `mt_rand` If you're interested I can send a PR.
kerem closed this issue 2026-02-25 20:32:11 +03:00
Author
Owner

@base-zero commented on GitHub (May 9, 2016):

👍

<!-- gh-comment-id:217891491 --> @base-zero commented on GitHub (May 9, 2016): 👍
Author
Owner

@overint commented on GitHub (Jun 1, 2016):

This should definitely be changed. @aik099 did you create a pull request?

<!-- gh-comment-id:222891998 --> @overint commented on GitHub (Jun 1, 2016): This should definitely be changed. @aik099 did you create a pull request?
Author
Owner

@aik099 commented on GitHub (Jun 1, 2016):

I haven't yet. If you'd like I can create it this week.

<!-- gh-comment-id:222917480 --> @aik099 commented on GitHub (Jun 1, 2016): I haven't yet. If you'd like I can create it this week.
Author
Owner

@aik099 commented on GitHub (Jun 1, 2016):

PR created and ready for review.

<!-- gh-comment-id:223043483 --> @aik099 commented on GitHub (Jun 1, 2016): PR created and ready for review.
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/google2fa#11
No description provided.