Thank you for the details! I now understand the issue and can reproduce it — which means I could solve it. I will try to explain the nature of the issue, how I solved it and what to do.
The nature of the issue
Back in 2012 I contributed the Two Factor Authentication (TFA) feature in Joomla 3.2. There was a requirement to store its information encrypted in the database. We implemented that, using mCrypt and the site's secret as the key. Come PHP 7.0 the PHP project decided to drop mCrypt as an official extension since it had not been actively maintained from 2007 onwards. A decision was made to drop the encryption of TFA settings altogether as of Joomla 3.6.4.
When Akeeba Backup restores a backup archive it changes the site's secret. This is a security setting since the secret is also used to key the login cookies. If you have two sites with the same site secret and the same user ID you can take the login cookie from one site and use it on the other one to become logged in as that user without knowing its username, password or TFA code.
However, changing the secret means that any TFA created with Joomla 3.2 to 3.6.3 inclusive by a user who has not logged into the site since Joomla 3.6.4 was released needs to be decrypted with the old site secret and re–encrypted with the new secret. Back when Joomla 3.6 and 3.7 were fresh out of the oven it made sense so that's what we did.
Because of the way Joomla implements the decryption and the way PHP 8 treats undefined constants as fatal errors instead of PHP notices this code started breaking the restoration on PHP 8. I reported this issue to Joomla — since it affects Joomla itself — but the consensus is that probably no action will be taken other than removing the legacy TFA encryption code since it actually never really worked right in Joomla.
We tried to apply a workaround in our restoration script which does work with most Joomla 4 sites. Obviously it didn't work on your site and it's very likely that it won't work on some other sites since it's a very finicky thing trying to address a multitude of Joomla versions.
How we solved it
Your ticket made me think. Does having this code even make any sense anymore?
We have to consider that this code only makes sense if you have users who set up TFA before Joomla 3.6.4 and have not logged into the site at all ever since. So, we are talking about users who set up TFA between late 2012 and October 2016 and have not logged into the site since October 2016. October 2016 was five years ago. Someone not logging in for a year or two, maybe three if we are pushing it, is understandable. After five years we can most definitely consider this user account abandoned and not care about its TFA being broken. If they really want to log in after all those years they can contact the site administrator to reset TFA on their account.
So, my decision was to completely remove that code.
TL;DR — What you can do next
Please download and install the latest dev release from https://www.akeeba.com/download/developer-releases/akeebabackuppro-dev/rev56f77d8.html
Take a new backup with it.
Restoring it should work just fine.
Please confirm.
Thank you very much for your issue report and thank you in advance for your feedback!
Nicholas K. Dionysopoulos
Lead Developer and Director
🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!