2014-07-01 14:37:52 +00:00
|
|
|
|
|
|
|
function decode(url) {
|
|
|
|
// otpauth://totp/user@host.com?secret=JBSWY3DPEHPK3PXP
|
|
|
|
// otpauth://totp/user@host.com?secret=JBSWY3DPEHPK3PXP
|
|
|
|
|
|
|
|
if (url.search(/^otpauth:\/\/[th]otp\/.*?.*/) != -1) {
|
|
|
|
var ret = {"type": "", "title": "", "secret": "", "counter": ""};
|
|
|
|
ret.type = url.slice(10,14).toUpperCase();
|
2015-05-22 17:09:07 +00:00
|
|
|
ret.title = decodeURIComponent(url.slice(15, url.indexOf("?")));
|
2014-07-01 14:37:52 +00:00
|
|
|
var pstr = url.slice(url.indexOf("?")+1, url.length);
|
|
|
|
var params = pstr.split("&");
|
|
|
|
|
|
|
|
for (var i = 0; i < params.length; ++i) {
|
|
|
|
pstr = params[i];
|
|
|
|
var tmp = pstr.split("=");
|
|
|
|
if (tmp[0] == "secret") ret.secret = tmp[1];
|
|
|
|
if (tmp[0] == "counter") ret.counter = tmp[1];
|
2016-07-17 17:35:53 +00:00
|
|
|
if (tmp[0] == "digits") ret.digits = tmp[1];
|
2014-07-01 14:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|