Skip to content

Instantly share code, notes, and snippets.

@Max1Truc
Last active August 19, 2019 13:23
Show Gist options
  • Save Max1Truc/bfc7584e2731354c498333ef497d59aa to your computer and use it in GitHub Desktop.
Save Max1Truc/bfc7584e2731354c498333ef497d59aa to your computer and use it in GitHub Desktop.
JavaScript script to convert Google Authenticator database to a format the Authenticator extension can read
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/0.5.0/js/sql.js">
</script>
<title></title>
</head>
<body>
<input type="file">
<p hidden>
<a href="#" download>Download</a> as Two Factor Authenticator's exported settings
</p>
<script>
function loadDB(db) {
infos = db.exec("SELECT email, secret FROM accounts")[0].values;
for (var x in infos) {
infos[x] = {
"name": (infos[x][0] != "null" ? infos[x][0] : infos[x][2]),
// For key's name use "email" but in some cases it can be
// null so program will use "issuer"
"key": infos[x][1]
}
}
infos = {
otp_list: infos
};
document.getElementsByTagName("a")[0].href = "data:text/json;charset=utf-8," + JSON.stringify(infos);
document.getElementsByTagName("p")[0].removeAttribute("hidden");
document.getElementsByTagName("input")[0].setAttribute("hidden", "");
}
document.getElementsByTagName("input")[0].onchange = function() {
var f = document.getElementsByTagName("input")[0].files[0];
var r = new FileReader();
r.onload = function() {
var Uints = new Uint8Array(r.result);
loadDB(new SQL.Database(Uints));
}
r.readAsArrayBuffer(f);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment