Single-sign-on and self-serve account management. https://netsyms.biz/apps/accounthub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoginKeys.lib.php 989B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /*
  3. * This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. */
  7. class LoginKey {
  8. public static function generate(string $appname, $appicon = null): string {
  9. global $database;
  10. do {
  11. $code = base64_encode(random_bytes(32));
  12. } while ($database->has('userloginkeys', ['key' => $code]));
  13. $database->insert('userloginkeys', ['key' => $code, 'expires' => date("Y-m-d H:i:s", time() + 600), 'appname' => $appname, 'appicon' => $appicon]);
  14. return $code;
  15. }
  16. public static function getuid(string $code): int {
  17. global $database;
  18. if (!$database->has('userloginkeys', ["AND" => ['key' => $code, 'uid[!]' => null]])) {
  19. throw new Exception();
  20. }
  21. $uid = $database->get('userloginkeys', 'uid', ['key' => $code]);
  22. return $uid;
  23. }
  24. }