[php] 123

Viewer

  1. if (isset($_GET['webauthn'])) {
  2. try {
  3. $webauthn = new \Davidearl\WebAuthn\WebAuthn($_SERVER['HTTP_HOST']);
  4. switch(TRUE){
  5. case isset($_POST['checkmfa']):
  6. $key = $core->query('SELECT webauthnkeys FROM accounts WHERE id = ? LIMIT 1', $data['id'])->fetchArray();
  7. $j['challenge'] = $webauthn->prepareForLogin($key['webauthnkeys']);
  8. break;
  9. case isset($_POST['confirmcheck']):
  10. $key = $core->query('SELECT webauthnkeys FROM accounts WHERE id = ? LIMIT 1', $data['id'])->fetchArray();
  11. if (! $webauthn->authenticate($_POST['confirmcheck'], $key['webauthnkeys'])) {
  12. http_response_code(401);
  13. echo 'failed to authenticate with that key';
  14. exit;
  15. }
  16. $j = 'ok';
  17. // Login
  18.  
  19. session_regenerate_id();
  20. $_SESSION['loggedin'] = TRUE;
  21. $_SESSION['name'] = $data['username'];
  22. $_SESSION['id'] = $data['id'];
  23. break;
  24. default:
  25. http_response_code(400);
  26. echo "unrecognized POST\n";
  27. break;
  28. }
  29. } catch(Exception $ex) {
  30. oops($ex->getMessage());
  31. }
  32. }

Editor

You can edit this paste and save as new:


File Description
  • 123
  • Paste Code
  • 14 Jun-2021
  • 941 Bytes
You can Share it: