1
0
Fork 0
mirror of https://github.com/seiichiro0185/sailotp.git synced 2024-11-22 07:39:42 +00:00

Added SteamGuard as new OTP Type

This commit is contained in:
seiichiro 2015-12-06 18:47:13 +01:00
parent 3561d57d63
commit 4817aea2f7
4 changed files with 12 additions and 27 deletions

View file

@ -41,15 +41,9 @@ CoverBackground {
function updateOTP() { function updateOTP() {
// get seconds from current Date // get seconds from current Date
var curDate = new Date(); var curDate = new Date();
var type;
if (lOTP.text == "------" || curDate.getSeconds() == 30 || curDate.getSeconds() == 0 || (curDate.getTime() - lastUpdated > 2000)) { if (lOTP.text == "------" || curDate.getSeconds() == 30 || curDate.getSeconds() == 0 || (curDate.getTime() - lastUpdated > 2000)) {
if (appWin.coverTitle.substr(0,6) == "Steam:") { appWin.coverOTP = OTP.calcOTP(appWin.coverSecret, appWin.coverType, 0);
type = "TOTP_STEAM"
} else {
type = "TOTP"
}
appWin.coverOTP = OTP.calcOTP(appWin.coverSecret, type, 0);
} }
// Change color of the OTP to red if less than 5 seconds left // Change color of the OTP to red if less than 5 seconds left
@ -65,7 +59,7 @@ CoverBackground {
Timer { Timer {
interval: 1000 interval: 1000
// Timer runs only when cover is visible and favourite is set // Timer runs only when cover is visible and favourite is set
running: !Qt.application.active && appWin.coverSecret != "" && appWin.coverType == "TOTP" running: !Qt.application.active && appWin.coverSecret != "" && (appWin.coverType == "TOTP" || appWin.coverType == "TOTP_STEAM")
repeat: true repeat: true
onTriggered: updateOTP(); onTriggered: updateOTP();
} }
@ -113,7 +107,7 @@ CoverBackground {
if (index < 0) index = appWin.listModel.count - 1 if (index < 0) index = appWin.listModel.count - 1
appWin.setCover(index); appWin.setCover(index);
DB.setFav(appWin.coverTitle, appWin.coverSecret) DB.setFav(appWin.coverTitle, appWin.coverSecret)
if (appWin.coverType == "TOTP") updateOTP(); if (appWin.coverType == "TOTP" || appWin.coverType == "TOTP_STEAM") updateOTP();
} }
} }
} }
@ -124,7 +118,7 @@ CoverBackground {
if (index >= appWin.listModel.count) index = 0 if (index >= appWin.listModel.count) index = 0
appWin.setCover(index); appWin.setCover(index);
DB.setFav(appWin.coverTitle, appWin.coverSecret) DB.setFav(appWin.coverTitle, appWin.coverSecret)
if (appWin.coverType == "TOTP") updateOTP(); if (appWin.coverType == "TOTP" || appWin.coverType == "TOTP_STEAM") updateOTP();
} }
} }
} }

View file

@ -200,13 +200,10 @@ function changeOTP(title, secret, type, counter, oldtitle, oldsecret) {
db.transaction( db.transaction(
function(tx) { function(tx) {
if (checkOTP(title, secret)) {
console.log("Token " + title + " is already in DB");
} else {
tx.executeSql("UPDATE OTPStorage SET title=?, secret=?, type=?, counter=? WHERE title=? and secret=?;", [title, secret, type, counter, oldtitle, oldsecret]); tx.executeSql("UPDATE OTPStorage SET title=?, secret=?, type=?, counter=? WHERE title=? and secret=?;", [title, secret, type, counter, oldtitle, oldsecret]);
console.log("Token " + title + " modified."); console.log("Token " + title + " modified.");
} }
}); );
} }
function changeOTPSort(title, secret, sort) { function changeOTPSort(title, secret, sort) {

View file

@ -67,7 +67,7 @@ Dialog {
MenuItem { MenuItem {
text: qsTr("Show QR-Code") text: qsTr("Show QR-Code")
onClicked: { onClicked: {
if ((paramType == "TOTP" && (otpLabel.text == "" || otpSecret.text == "")) || (paramType == "HOTP" && (otpLabel.text == "" || otpSecret.text == "" || otpCounter.text <= 0))) { if (((paramType == "TOTP" || paramType == "TOTP_STEAM") && (otpLabel.text == "" || otpSecret.text == "")) || (paramType == "HOTP" && (otpLabel.text == "" || otpSecret.text == "" || otpCounter.text <= 0))) {
notify.show(qsTr("Can't create QR-Code from incomplete settings!"), 4000); notify.show(qsTr("Can't create QR-Code from incomplete settings!"), 4000);
} else { } else {
pageStack.push(Qt.resolvedUrl("QRPage.qml"), {paramLabel: otpLabel.text, paramKey: otpSecret.text, paramType: paramType, paramCounter: otpCounter.text}); pageStack.push(Qt.resolvedUrl("QRPage.qml"), {paramLabel: otpLabel.text, paramKey: otpSecret.text, paramType: paramType, paramCounter: otpCounter.text});
@ -90,6 +90,7 @@ Dialog {
menu: ContextMenu { menu: ContextMenu {
MenuItem { text: qsTr("Time-based (TOTP)"); onClicked: { paramType = "TOTP" } } MenuItem { text: qsTr("Time-based (TOTP)"); onClicked: { paramType = "TOTP" } }
MenuItem { text: qsTr("Counter-based (HOTP)"); onClicked: { paramType = "HOTP" } } MenuItem { text: qsTr("Counter-based (HOTP)"); onClicked: { paramType = "HOTP" } }
MenuItem { text: qsTr("Steam Guard"); onClicked: { paramType = "TOTP_STEAM" } }
} }
} }
TextField { TextField {
@ -115,8 +116,8 @@ Dialog {
horizontalAlignment: TextInput.AlignLeft horizontalAlignment: TextInput.AlignLeft
EnterKey.enabled: text.length > 15 EnterKey.enabled: text.length > 15
EnterKey.iconSource: paramType == "TOTP" ? "image://theme/icon-m-enter-accept" : "image://theme/icon-m-enter-next" EnterKey.iconSource: paramType == "HOTP" ? "image://theme/icon-m-enter-next" : "image://theme/icon-m-enter-accept"
EnterKey.onClicked: paramType == "TOTP" ? addOTP.accept() : otpCounter.focus = true EnterKey.onClicked: paramType == "HOTP" ? otpCounter.focus = true : addOTP.accept()
} }
TextField { TextField {
id: otpCounter id: otpCounter
@ -137,7 +138,7 @@ Dialog {
} }
// Check if we can Save // Check if we can Save
canAccept: otpLabel.text.length > 0 && otpSecret.text.length >= 16 && (paramType == "TOTP" || otpCounter.text.length > 0) ? true : false canAccept: otpLabel.text.length > 0 && otpSecret.text.length >= 16 && (paramType == "TOTP" || paramType == "TOTP_STEAM" || otpCounter.text.length > 0) ? true : false
// Save if page is Left with Add // Save if page is Left with Add
onDone: { onDone: {

View file

@ -69,20 +69,13 @@ Page {
// get seconds from current Date // get seconds from current Date
var curDate = new Date(); var curDate = new Date();
var seconds = curDate.getSeconds(); var seconds = curDate.getSeconds();
var type;
// Iterate over all List entries // Iterate over all List entries
for (var i=0; i<appWin.listModel.count; i++) { for (var i=0; i<appWin.listModel.count; i++) {
if (appWin.listModel.get(i).type == "TOTP") { if (appWin.listModel.get(i).type == "TOTP" || appWin.listModel.get(i).type == "TOTP_STEAM" ) {
// Only update on full 30 / 60 Seconds or if last run of the Functions is more than 2s in the past (e.g. app was in background) // Only update on full 30 / 60 Seconds or if last run of the Functions is more than 2s in the past (e.g. app was in background)
if (appWin.listModel.get(i).otp == "------" || seconds == 30 || seconds == 0 || (curDate.getTime() - lastUpdated > 2000)) { if (appWin.listModel.get(i).otp == "------" || seconds == 30 || seconds == 0 || (curDate.getTime() - lastUpdated > 2000)) {
if (appWin.listModel.get(i).title.substr(0,6) == "Steam:") { var curOTP = OTP.calcOTP(appWin.listModel.get(i).secret, appWin.listModel.get(i).type)
type = "TOTP_STEAM"
} else {
type = "TOTP"
}
var curOTP = OTP.calcOTP(appWin.listModel.get(i).secret, type)
appWin.listModel.setProperty(i, "otp", curOTP); appWin.listModel.setProperty(i, "otp", curOTP);
} }
} else if (appWin.coverType == "HOTP" && (curDate.getTime() - lastUpdated > 2000) && appWin.listModel.get(i).fav == 1) { } else if (appWin.coverType == "HOTP" && (curDate.getTime() - lastUpdated > 2000) && appWin.listModel.get(i).fav == 1) {