RobThree / TwoFactorAuth

PHP library for Two Factor Authentication (TFA / 2FA)
MIT License
1.07k stars 126 forks source link

Fatal Error #26

Closed ukitconsultant closed 6 years ago

ukitconsultant commented 6 years ago

Hi there,

I'm getting the following;

Fatal error: Class 'RobThree\Auth\TwoFactorAuth' not found in /[REMOVED]/public_html/2fa.php on line 12

`

   <?php
    error_reporting(-1); 
    ini_set('display_errors', 1);

     require_once '2fa/demo/loader.php';
    Loader::register('2fa/lib','RobThree\\Auth');

    use \RobThree\Auth\TwoFactorAuth;

    $tfa = new TwoFactorAuth('MyApp');

    // Generate the code, store it inside the database, 
    // and generate the QR code for the user to scan, or provide the code
    // for the user to manually type into the app being used.

    // Generate User Image
    $secret = $tfa->createSecret(160);

echo "Two Factor Authentication Platform<br /><br />";
    echo "Secret Generated: " . $secret;
    echo "<br /><br /><br />";
    echo "Code for App: " . chunk_split($secret, 4, ' ');`
RobThree commented 6 years ago

Are the files where they are supposed to be? Do the files have the correct permissions? What have you tried to troubleshoot this problem yourself?

ukitconsultant commented 6 years ago

Yes, yes and I’ve tried them in different locations, on five separate servers with the same end result.

willpower232 commented 6 years ago

Evidently Loader::register() is not locating or including the appropriate PHP files from this library.

Is it from a particular framework? You should review the documentation or the code itself to see where you should put the files.

ukitconsultant commented 6 years ago

Yep, I got that far on my own, the why is the issue.

I’m running it outside of any framework, just a singular php file calling the code which was copied from the demo file, and then altered two loading filepaths to suit the correct file paths on the various file systems, each one produced the same error. I retrieved it using the latest version of composer in each case, and have run file comparisons between the files retrieved in different locations, and each one compared up without any issues.

Eventually this would have gone into a library for codeigniter, but alas, I can’t even get the loader to work, and loathe to use a different loader, given that code igniter doesn’t have a loader in v3.

willpower232 commented 6 years ago

I have been able to replicate this and the answer is that the path to Loader::register() must apparently be from loader.php, not where the script is being called from.

Ergo, it should be ../lib.

An enhancement would be to update loader.php to remove the reliance on $parentPath.

ukitconsultant commented 6 years ago

Ah, okay. I did think that, but didn’t try it, basically time got away from me.

I’ll make the changes now and give it a go!

RobThree commented 6 years ago

@ukitconsultant Could you, please, for the love of <your_deity_here> get rid of this stupendously big email footer of yours or at least have the courtesy to delete it before replying? This is ridiculous. I have removed them from all your messages, FYI.

I’ll make the changes now and give it a go!

Let us know if it worked!

RobThree commented 6 years ago

Assuming PEBKAC 😜