Last active
August 19, 2019 13:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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