-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotp_demo.html
More file actions
476 lines (437 loc) · 21 KB
/
Copy pathotp_demo.html
File metadata and controls
476 lines (437 loc) · 21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OTP Authentication – JV Shetty</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Inter', sans-serif;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 50%, #6d28d9 100%);
position: relative;
overflow: hidden;
padding: 2rem 1rem;
}
body::before {
content: '';
position: absolute;
top: 0; left: 0;
width: 24rem; height: 24rem;
border-radius: 50%;
background: rgba(255,255,255,0.05);
filter: blur(48px);
transform: translate(-50%, -50%);
pointer-events: none;
}
body::after {
content: '';
position: absolute;
bottom: 0; right: 0;
width: 20rem; height: 20rem;
border-radius: 50%;
background: rgba(196,181,253,0.1);
filter: blur(48px);
transform: translate(50%, 50%);
pointer-events: none;
}
.wrap { position: relative; width: 100%; max-width: 440px; }
.card {
background: #fff;
border-radius: 1.5rem;
box-shadow: 0 25px 50px rgba(0,0,0,0.25);
overflow: hidden;
margin-bottom: 12px;
}
.card-header {
background: linear-gradient(to right, #7c3aed, #4f46e5);
padding: 2rem;
text-align: center;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; margin-bottom: 4px; }
.brand-icon {
width: 40px; height: 40px;
border-radius: 12px;
background: rgba(255,255,255,0.2);
display: flex; align-items: center; justify-content: center;
}
.brand-icon i { color: #fff; font-size: 18px; }
.brand-name { font-size: 22px; font-weight: 800; color: #fff; letter-spacing: -0.5px; }
.card-header p { color: #ddd6fe; font-size: 13px; margin-top: 8px; }
.card-body { padding: 2rem; }
.alert {
display: flex; align-items: flex-start; gap: 10px;
padding: 14px 16px; border-radius: 14px; font-size: 13px; margin-bottom: 1.25rem;
}
.alert-err { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; }
.alert-warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: #15803d; }
.alert i { flex-shrink: 0; margin-top: 1px; }
.field { margin-bottom: 1.1rem; }
label { display: block; font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.input-wrap { position: relative; }
.input-wrap .ico {
position: absolute; left: 14px; top: 50%;
transform: translateY(-50%);
color: #9ca3af; font-size: 14px; pointer-events: none;
}
input[type=email], input[type=text] {
width: 100%;
padding: 11px 16px 11px 40px;
border: 2px solid #e5e7eb;
border-radius: 12px;
font-size: 14px;
font-family: 'Inter', sans-serif;
color: #111827;
outline: none;
transition: border-color 0.2s, box-shadow 0.2s;
background: #fff;
}
input[type=email]:focus, input[type=text]:focus {
border-color: #7c3aed;
box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}
.hint { font-size: 11px; color: #9ca3af; margin-top: 4px; }
.btn {
width: 100%; padding: 13px; border: none; border-radius: 12px;
font-size: 14px; font-weight: 700; font-family: 'Inter', sans-serif;
cursor: pointer; transition: all 0.25s;
display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary {
background: linear-gradient(to right, #7c3aed, #4f46e5);
color: #fff;
box-shadow: 0 8px 20px rgba(124,58,237,0.3);
margin-top: 4px;
}
.btn-primary:hover { background: linear-gradient(to right, #6d28d9, #4338ca); box-shadow: 0 10px 24px rgba(124,58,237,0.4); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.btn-ghost {
background: transparent; border: 2px solid #e5e7eb;
color: #6b7280; font-size: 13px; padding: 10px; margin-top: 0;
}
.btn-ghost:hover { border-color: #7c3aed; color: #7c3aed; }
/* OTP digit boxes */
.otp-row { display: flex; gap: 8px; justify-content: center; margin: 14px 0; }
.otp-row input {
width: 52px; height: 58px;
text-align: center; font-size: 22px; font-weight: 700;
padding: 0; border: 2px solid #e5e7eb; border-radius: 12px;
color: #111827; font-family: 'Inter', sans-serif; outline: none;
transition: border-color 0.2s, box-shadow 0.2s;
}
.otp-row input:focus { border-color: #7c3aed; box-shadow: 0 0 0 3px rgba(124,58,237,0.1); }
.otp-row input:disabled { background: #f9fafb; opacity: 0.5; }
/* OTP reveal */
.otp-reveal-label { font-size: 11px; color: #7c3aed; font-weight: 600; text-align: center; margin-bottom: 2px; }
.otp-reveal {
background: #f5f3ff; border: 1.5px dashed #c4b5fd;
border-radius: 12px; padding: 12px; text-align: center;
font-size: 28px; font-weight: 700; letter-spacing: 10px;
color: #5b21b6; margin-bottom: 4px;
}
/* Timer */
.timer-track { background: #f3f4f6; border-radius: 4px; height: 4px; overflow: hidden; margin-bottom: 6px; }
.timer-fill { height: 100%; border-radius: 4px; background: linear-gradient(to right,#7c3aed,#4f46e5); transition: width 1s linear, background 0.3s; }
.timer-row { display: flex; justify-content: space-between; align-items: center; }
.timer-text { font-size: 12px; color: #6b7280; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 10px; border-radius: 20px; }
.badge-ok { background: #f0fdf4; color: #15803d; }
.badge-err { background: #fef2f2; color: #b91c1c; }
/* Stats card */
.card2 {
background: #fff; border-radius: 1.5rem;
box-shadow: 0 10px 30px rgba(0,0,0,0.12); padding: 1.25rem;
}
.stats-row { display: flex; gap: 10px; margin-bottom: 12px; }
.stat-box { flex: 1; background: #f9fafb; border-radius: 10px; padding: 10px 12px; }
.stat-box .num { font-size: 20px; font-weight: 700; color: #111827; }
.stat-box .lbl { font-size: 11px; color: #9ca3af; margin-top: 1px; }
.log-wrap {
background: #f9fafb; border-radius: 10px;
padding: 10px 12px; font-size: 11.5px;
font-family: 'Courier New', monospace;
max-height: 120px; overflow-y: auto;
}
.log-wrap div { padding: 2px 0; border-bottom: 1px solid #f3f4f6; color: #6b7280; }
.log-wrap div:last-child { border: none; }
.lev-send { color: #4f46e5 !important; }
.lev-ok { color: #15803d !important; }
.lev-fail { color: #b91c1c !important; }
.lev-lock { color: #92400e !important; }
.resend { font-size: 13px; color: #9ca3af; text-align: center; margin-top: 12px; }
.resend span { color: #7c3aed; cursor: pointer; font-weight: 600; }
.resend span.off { color: #d1d5db; cursor: default; font-weight: 400; }
.divider { border: none; border-top: 1px solid #f3f4f6; margin: 16px 0; }
.jwt-box { background: #f5f3ff; border-radius: 12px; padding: 12px; margin: 12px 0 16px; text-align: left; }
.jwt-lbl { font-size: 11px; color: #7c3aed; font-weight: 600; margin-bottom: 4px; }
.jwt-val { font-size: 10.5px; font-family: 'Courier New', monospace; color: #5b21b6; word-break: break-all; }
.footer-note { text-align: center; color: rgba(255,255,255,0.6); font-size: 12px; margin-top: 16px; }
.center { text-align: center; }
.icon-xl { font-size: 36px; margin-bottom: 8px; display: block; }
.screen { display: none; }
.screen.active { display: block; }
</style>
</head>
<body>
<div class="wrap">
<!-- ── Login / Send OTP ── -->
<div id="s-login" class="screen active">
<div class="card">
<div class="card-header">
<a class="brand" href="#"><div class="brand-icon"><i class="bi bi-shop"></i></div><span class="brand-name">JV Shetty</span></a>
<p>Sign in to your campus account</p>
</div>
<div class="card-body">
<div id="login-alert" style="display:none"></div>
<div class="field">
<label for="email-input">Campus Email</label>
<div class="input-wrap">
<i class="bi bi-envelope ico"></i>
<input type="email" id="email-input" placeholder="f20xxxxxx@goa.bits-pilani.ac.in" value="student@goa.bits-pilani.ac.in" />
</div>
<p class="hint">Only @goa.bits-pilani.ac.in addresses</p>
</div>
<button class="btn btn-primary" onclick="sendOTP()">
<i class="bi bi-shield-lock"></i> Send OTP
</button>
<p class="center" style="font-size:13px;color:#9ca3af;margin-top:16px;">
Don't have an account? <a href="#" style="color:#7c3aed;font-weight:600;">Create one</a>
</p>
</div>
</div>
<div class="card2">
<div class="stats-row">
<div class="stat-box"><div class="num" id="stat-req">0</div><div class="lbl">OTP requests (max 3/hr)</div></div>
<div class="stat-box"><div class="num" id="stat-fail">0</div><div class="lbl">Failed attempts (lock at 5)</div></div>
</div>
<label style="margin-bottom:6px">Event log</label>
<div class="log-wrap" id="event-log"><div style="color:#d1d5db">No events yet</div></div>
</div>
</div>
<!-- ── OTP Entry ── -->
<div id="s-otp" class="screen">
<div class="card">
<div class="card-header">
<a class="brand" href="#"><div class="brand-icon"><i class="bi bi-shop"></i></div><span class="brand-name">JV Shetty</span></a>
<p>Enter the code sent to your campus email</p>
</div>
<div class="card-body">
<div id="otp-alert" style="display:none"></div>
<p style="font-size:13px;color:#6b7280;margin-bottom:10px;">Code sent to <strong id="sent-to" style="color:#111827"></strong></p>
<div class="otp-reveal-label"><i class="bi bi-eye"></i> OTP shown for demo</div>
<div class="otp-reveal" id="otp-reveal">——</div>
<label style="margin-top:8px">Enter 6-digit OTP</label>
<div class="otp-row" id="otp-boxes">
<input type="text" maxlength="1" oninput="otpIn(this,0)" onkeydown="otpKd(event,this,0)" />
<input type="text" maxlength="1" oninput="otpIn(this,1)" onkeydown="otpKd(event,this,1)" />
<input type="text" maxlength="1" oninput="otpIn(this,2)" onkeydown="otpKd(event,this,2)" />
<input type="text" maxlength="1" oninput="otpIn(this,3)" onkeydown="otpKd(event,this,3)" />
<input type="text" maxlength="1" oninput="otpIn(this,4)" onkeydown="otpKd(event,this,4)" />
<input type="text" maxlength="1" oninput="otpIn(this,5)" onkeydown="otpKd(event,this,5)" />
</div>
<div style="margin:4px 0 10px;">
<div class="timer-track"><div class="timer-fill" id="t-bar" style="width:100%"></div></div>
<div class="timer-row">
<span class="timer-text">Expires in <span id="t-text">10:00</span></span>
<span class="badge badge-ok" id="t-badge">Valid</span>
</div>
</div>
<button class="btn btn-primary" id="btn-verify" onclick="verifyOTP()" disabled>
<i class="bi bi-box-arrow-in-right"></i> Verify & Sign In
</button>
<div class="resend">Didn't get it? <span id="resend-btn" onclick="doResend()" class="off">Resend OTP</span></div>
<div class="divider"></div>
<button class="btn btn-ghost" onclick="showScreen('s-login')"><i class="bi bi-arrow-left"></i> Back</button>
</div>
</div>
<div class="card2">
<div class="stats-row">
<div class="stat-box"><div class="num" id="stat-req2">0</div><div class="lbl">OTP requests (max 3/hr)</div></div>
<div class="stat-box"><div class="num" id="stat-fail2">0</div><div class="lbl">Failed attempts (lock at 5)</div></div>
</div>
<label style="margin-bottom:6px">Event log</label>
<div class="log-wrap" id="event-log2"><div style="color:#d1d5db">No events yet</div></div>
</div>
</div>
<!-- ── Locked ── -->
<div id="s-locked" class="screen">
<div class="card">
<div class="card-header">
<a class="brand" href="#"><div class="brand-icon"><i class="bi bi-shop"></i></div><span class="brand-name">JV Shetty</span></a>
<p>Account temporarily locked</p>
</div>
<div class="card-body center">
<i class="bi bi-lock-fill icon-xl" style="color:#7c3aed"></i>
<h2 style="font-size:18px;font-weight:700;margin-bottom:8px;color:#111827">Account Locked</h2>
<p style="font-size:13px;color:#6b7280;margin-bottom:12px;">Too many failed OTP attempts. Your account is locked for 1 hour to protect your security.</p>
<div class="alert alert-warn"><i class="bi bi-clock"></i><span>Locked until <strong id="lock-until"></strong></span></div>
<button class="btn btn-primary" onclick="resetDemo()"><i class="bi bi-arrow-clockwise"></i> Reset Demo</button>
</div>
</div>
</div>
<!-- ── Success ── -->
<div id="s-success" class="screen">
<div class="card">
<div class="card-header">
<a class="brand" href="#"><div class="brand-icon"><i class="bi bi-shop"></i></div><span class="brand-name">JV Shetty</span></a>
<p>Welcome back!</p>
</div>
<div class="card-body center">
<i class="bi bi-check-circle-fill icon-xl" style="color:#16a34a"></i>
<h2 style="font-size:18px;font-weight:700;margin-bottom:4px;color:#111827">Signed In</h2>
<p style="font-size:13px;color:#6b7280;margin-bottom:12px;">Welcome back, <strong id="success-email" style="color:#7c3aed"></strong></p>
<div class="jwt-box">
<div class="jwt-lbl"><i class="bi bi-key"></i> JWT session token (simulated)</div>
<div class="jwt-val" id="jwt-val"></div>
</div>
<p style="font-size:12px;color:#9ca3af;margin-bottom:16px;"><i class="bi bi-clock"></i> Session expires after <strong style="color:#374151">30 minutes</strong> of inactivity (REQ-6)</p>
<button class="btn btn-primary" onclick="resetDemo()"><i class="bi bi-box-arrow-right"></i> Sign Out & Reset Demo</button>
</div>
</div>
</div>
<p class="footer-note"><i class="bi bi-shield-check"></i> Secure campus-only access</p>
</div>
<script>
const OTP_TTL=600, MAX_REQ=3, MAX_FAIL=5;
let otp='', expiry=0, timerID=null, resendID=null;
let reqCount=0, failCount=0, locked=false, resendSec=0;
const evLogs=[];
function log(msg,type){
const t=new Date().toTimeString().slice(0,8);
evLogs.unshift({msg,type,t});
['event-log','event-log2'].forEach(id=>{
const el=document.getElementById(id);
if(el) el.innerHTML=evLogs.slice(0,20).map(l=>`<div class="lev-${l.type}">${l.t} — ${l.msg}</div>`).join('');
});
}
function updateStats(){
['stat-req','stat-req2'].forEach(id=>{const el=document.getElementById(id);if(el)el.textContent=reqCount;});
['stat-fail','stat-fail2'].forEach(id=>{const el=document.getElementById(id);if(el)el.textContent=failCount;});
}
function showScreen(id){
document.querySelectorAll('.screen').forEach(s=>s.classList.remove('active'));
document.getElementById(id).classList.add('active');
}
function showAlert(cid,msg,type){
const icons={err:'exclamation-circle-fill',warn:'exclamation-triangle-fill',ok:'check-circle-fill'};
const el=document.getElementById(cid);
if(!el)return;
el.innerHTML=`<div class="alert alert-${type}"><i class="bi bi-${icons[type]}"></i><span>${msg}</span></div>`;
el.style.display='block';
}
function clearAlert(id){const el=document.getElementById(id);if(el){el.innerHTML='';el.style.display='none';}}
function genOTP(){return String(Math.floor(100000+Math.random()*900000));}
function fakeJWT(email){
const h=btoa(JSON.stringify({alg:'HS256',typ:'JWT'}));
const p=btoa(JSON.stringify({sub:email,iat:Math.floor(Date.now()/1000),exp:Math.floor(Date.now()/1000)+1800}));
const s=btoa(Math.random().toString(36).slice(2,14)).replace(/=/g,'');
return `${h}.${p}.${s}`;
}
function sendOTP(){
if(locked)return;
const email=document.getElementById('email-input').value.trim()||'student@goa.bits-pilani.ac.in';
if(reqCount>=MAX_REQ){
showAlert('login-alert','Rate limit reached: max 3 OTP requests per hour (REQ-2C)','warn');
log('Rate limit hit — OTP blocked (429)','fail');return;
}
clearAlert('login-alert');
reqCount++;updateStats();
otp=genOTP();expiry=Date.now()+OTP_TTL*1000;
document.getElementById('sent-to').textContent=email;
document.getElementById('otp-reveal').textContent=otp;
clearAlert('otp-alert');
const boxes=document.querySelectorAll('#otp-boxes input');
boxes.forEach(b=>{b.value='';b.disabled=false;});
document.getElementById('btn-verify').disabled=true;
log(`OTP sent to ${email} (TTL 10 min, REQ-2A)`,'send');
showScreen('s-otp');startTimer();startResend();
setTimeout(()=>boxes[0].focus(),100);
}
function startTimer(){
if(timerID)clearInterval(timerID);
timerID=setInterval(()=>{
const rem=Math.max(0,Math.floor((expiry-Date.now())/1000));
const pct=(rem/OTP_TTL)*100;
const bar=document.getElementById('t-bar');
const badge=document.getElementById('t-badge');
bar.style.width=pct+'%';
if(pct<20){bar.style.background='#dc2626';badge.className='badge badge-err';badge.textContent='Expiring';}
else{bar.style.background='linear-gradient(to right,#7c3aed,#4f46e5)';badge.className='badge badge-ok';badge.textContent='Valid';}
const m=Math.floor(rem/60),s=rem%60;
document.getElementById('t-text').textContent=`${m}:${s.toString().padStart(2,'0')}`;
if(rem===0){
clearInterval(timerID);badge.className='badge badge-err';badge.textContent='Expired';
document.querySelectorAll('#otp-boxes input').forEach(b=>b.disabled=true);
document.getElementById('btn-verify').disabled=true;
showAlert('otp-alert','OTP expired. Please go back and request a new one.','err');
log('OTP expired (TTL 600s exceeded)','fail');
}
},1000);
}
function startResend(){
resendSec=30;
const btn=document.getElementById('resend-btn');
btn.className='off';btn.textContent=`Resend in ${resendSec}s`;
if(resendID)clearInterval(resendID);
resendID=setInterval(()=>{
resendSec--;
if(resendSec<=0){clearInterval(resendID);btn.textContent='Resend OTP';btn.className='';}
else btn.textContent=`Resend in ${resendSec}s`;
},1000);
}
function doResend(){if(resendSec>0)return;showScreen('s-login');sendOTP();}
function otpIn(el,idx){
el.value=el.value.replace(/\D/g,'').slice(-1);
const boxes=document.querySelectorAll('#otp-boxes input');
if(el.value&&idx<5)boxes[idx+1].focus();
document.getElementById('btn-verify').disabled=!Array.from(boxes).every(b=>b.value.length===1);
}
function otpKd(e,el,idx){
if(e.key==='Backspace'&&!el.value&&idx>0)document.querySelectorAll('#otp-boxes input')[idx-1].focus();
}
function verifyOTP(){
if(Date.now()>expiry){showAlert('otp-alert','OTP has expired. Please request a new one.','err');return;}
const entered=Array.from(document.querySelectorAll('#otp-boxes input')).map(b=>b.value).join('');
if(entered===otp){
clearInterval(timerID);
log('OTP verified — session created (JWT 30 min)','ok');
const email=document.getElementById('sent-to').textContent;
document.getElementById('success-email').textContent=email;
document.getElementById('jwt-val').textContent=fakeJWT(email);
showScreen('s-success');
} else {
failCount++;updateStats();
log(`Wrong OTP entered (attempt ${failCount}/${MAX_FAIL})`,'fail');
document.querySelectorAll('#otp-boxes input').forEach(b=>b.value='');
document.querySelectorAll('#otp-boxes input')[0].focus();
document.getElementById('btn-verify').disabled=true;
if(failCount>=MAX_FAIL){
locked=true;clearInterval(timerID);
log('Account LOCKED — 5 failures (UC-Auth)','lock');
document.getElementById('lock-until').textContent=new Date(Date.now()+3600000).toLocaleTimeString();
showScreen('s-locked');
} else {
const rem=MAX_FAIL-failCount;
showAlert('otp-alert',`Incorrect OTP. ${rem} attempt${rem!==1?'s':''} remaining.`,'err');
}
}
}
function resetDemo(){
if(timerID)clearInterval(timerID);if(resendID)clearInterval(resendID);
otp='';expiry=0;reqCount=0;failCount=0;locked=false;resendSec=0;evLogs.length=0;
['event-log','event-log2'].forEach(id=>{
const el=document.getElementById(id);if(el)el.innerHTML='<div style="color:#d1d5db">No events yet</div>';
});
clearAlert('login-alert');clearAlert('otp-alert');
updateStats();showScreen('s-login');
}
</script>
</body>
</html>