add otpauth

This commit is contained in:
AJ ONeal 2015-10-23 00:58:19 -07:00
parent 5dfb802d97
commit 9c3ee18ff4
2 changed files with 7 additions and 9 deletions

View File

@ -16,6 +16,7 @@
<img alt="qrcode" class="js-qrcode" width="166" height="166" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" />
<p>20-byte (160-bit) Base32 Key:</p>
<h3 class="js-key">xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx</h3>
<p class="js-otpauth">otpauth://totp/company:user?secret=xxxx</p>
</div>
<br />

15
test.js
View File

@ -16,16 +16,13 @@ function generate(ke) {
var userAccount = $('.js-user-account').value;
// obviously don't use this in production, but it's not so bad for the demo
var src = 'https://www.google.com/chart?chs=166x166&chld=L|0&cht=qr&chl='
+ encodeURIComponent(
'otpauth://totp/'
+ encodeURIComponent(companyName)
+ ':'
+ encodeURIComponent(userAccount)
+ '?secret='
+ key.replace(/\s+/g, '').toUpperCase()
);
var otpauth = 'otpauth://totp/'
+ encodeURIComponent(companyName) + ':' + encodeURIComponent(userAccount)
+ '?secret=' + key.replace(/\s+/g, '').toUpperCase()
;
var src = 'https://www.google.com/chart?chs=166x166&chld=L|0&cht=qr&chl=' + encodeURIComponent(otpauth);
$('.js-otpauth').innerHTML = otpauth; // safe to inject because I created it
$('.js-key').innerHTML = key; // safe to inject because I created it
$('img.js-qrcode').src = src;