forked from jiangts/JS-OTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
100 lines (85 loc) · 2.52 KB
/
index.html
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
<html><head>
<title>JS OTP Demo</title>
<style>
body {
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body style="width: 45em;">
<h1 id="jsotp-demo">JS OTP Demo</h1>
<p>Javascript Implementation of 2 Factor Auth</p>
<hr>
<p id="secret">Secret: </p>
<h2 id="code-1">TOTP code</h2>
<p id="ticker">timer</p>
<hr>
<p id="secret-2">Secret: </p>
<h2 id="code-2">HOTP code</h2>
<p>Counter value is: <span id="counter"></span></p>
<button onclick="requestHotp()">Get new code</button>
<script src="dist/jsOTP.min.js"></script>
<script>
$ = function(sel) {
return document.querySelector(sel);
};
var secret = "23TplPdS46Juzcyx"
$('#secret').innerText = "Secret: " + secret;
var totp = new jsOTP.totp();
var code = totp.getOtp(secret);
var hotp = new jsOTP.hotp();
var doge = hotp.getOtp(secret, 0);
console.log(code);
console.log(doge);
var updateTicker = function(tick, el) {
el.innerText = tick;
}
var updateTotp = function(secret, el) {
el.innerText = totp.getOtp(secret);
}
updateTotp(secret, $('#code-1'));
var timeLoop = function() {
var epoch = Math.round(new Date().getTime() / 1000.0);
var countDown = 30 - (epoch % 30);
updateTicker(countDown, $('#ticker'));
if (epoch % 30 == 0) updateTotp(secret, $('#code-1'));
}
setInterval(timeLoop, 1000);
var counter = 0;
var secret2 = "abcdefghijklmnop";
$('#secret-2').innerText = "Secret: " + secret2;
$('#counter').innerText = counter;
var updateHotp = function(secret, counter, el) {
el.innerText = hotp.getOtp(secret, counter);
}
var updateCounter = function(counter, el) {
el.innerText = counter;
}
var requestHotp = function() {
updateHotp(secret2, counter, $('#code-2'));
updateCounter(++counter, $('#counter'));
}
//TODO implement this. The problem is that not all secrets are valid...
/*
getSecret = function() {
var secret = prompt("Enter secret");
$('#secret-3').innerHTML = secret;
if(totpManager.accounts.length === 3)
totpManager.accounts.pop();
totpManager.add(secret, $('#code-3'), $('#ticker-3'));
$('#qr-3').src = 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chl=200x200&chld=M|0&cht=qr&chl=otpauth://totp/[email protected]%3Fsecret%3D' + secret;
}
*/
</script>
<!--
<hr>
<button type="button" onclick="getSecret()">Try your own secret</button>
<p id="secret-3"></p>
<h2 id="code-3"></h2>
<p id="ticker-3"></p>
<br>
<p>To verify it, you can scan the following QR code with your Google Authenticator app. The codes on this page and your app should match.</p>
<img id="qr-3"></img>
-->
</body></html>