mirror of
https://github.com/seiichiro0185/sailotp.git
synced 2024-12-22 03:32:30 +00:00
Added SteamGuard as new OTP Type
This commit is contained in:
parent
3561d57d63
commit
4817aea2f7
4 changed files with 12 additions and 27 deletions
|
@ -41,15 +41,9 @@ CoverBackground {
|
|||
function updateOTP() {
|
||||
// get seconds from current Date
|
||||
var curDate = new Date();
|
||||
var type;
|
||||
|
||||
if (lOTP.text == "------" || curDate.getSeconds() == 30 || curDate.getSeconds() == 0 || (curDate.getTime() - lastUpdated > 2000)) {
|
||||
if (appWin.coverTitle.substr(0,6) == "Steam:") {
|
||||
type = "TOTP_STEAM"
|
||||
} else {
|
||||
type = "TOTP"
|
||||
}
|
||||
appWin.coverOTP = OTP.calcOTP(appWin.coverSecret, type, 0);
|
||||
appWin.coverOTP = OTP.calcOTP(appWin.coverSecret, appWin.coverType, 0);
|
||||
}
|
||||
|
||||
// Change color of the OTP to red if less than 5 seconds left
|
||||
|
@ -65,7 +59,7 @@ CoverBackground {
|
|||
Timer {
|
||||
interval: 1000
|
||||
// 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
|
||||
onTriggered: updateOTP();
|
||||
}
|
||||
|
@ -113,7 +107,7 @@ CoverBackground {
|
|||
if (index < 0) index = appWin.listModel.count - 1
|
||||
appWin.setCover(index);
|
||||
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
|
||||
appWin.setCover(index);
|
||||
DB.setFav(appWin.coverTitle, appWin.coverSecret)
|
||||
if (appWin.coverType == "TOTP") updateOTP();
|
||||
if (appWin.coverType == "TOTP" || appWin.coverType == "TOTP_STEAM") updateOTP();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,13 +200,10 @@ function changeOTP(title, secret, type, counter, oldtitle, oldsecret) {
|
|||
|
||||
db.transaction(
|
||||
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]);
|
||||
console.log("Token " + title + " modified.");
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
function changeOTPSort(title, secret, sort) {
|
||||
|
|
|
@ -67,7 +67,7 @@ Dialog {
|
|||
MenuItem {
|
||||
text: qsTr("Show QR-Code")
|
||||
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);
|
||||
} else {
|
||||
pageStack.push(Qt.resolvedUrl("QRPage.qml"), {paramLabel: otpLabel.text, paramKey: otpSecret.text, paramType: paramType, paramCounter: otpCounter.text});
|
||||
|
@ -90,6 +90,7 @@ Dialog {
|
|||
menu: ContextMenu {
|
||||
MenuItem { text: qsTr("Time-based (TOTP)"); onClicked: { paramType = "TOTP" } }
|
||||
MenuItem { text: qsTr("Counter-based (HOTP)"); onClicked: { paramType = "HOTP" } }
|
||||
MenuItem { text: qsTr("Steam Guard"); onClicked: { paramType = "TOTP_STEAM" } }
|
||||
}
|
||||
}
|
||||
TextField {
|
||||
|
@ -115,8 +116,8 @@ Dialog {
|
|||
horizontalAlignment: TextInput.AlignLeft
|
||||
|
||||
EnterKey.enabled: text.length > 15
|
||||
EnterKey.iconSource: paramType == "TOTP" ? "image://theme/icon-m-enter-accept" : "image://theme/icon-m-enter-next"
|
||||
EnterKey.onClicked: paramType == "TOTP" ? addOTP.accept() : otpCounter.focus = true
|
||||
EnterKey.iconSource: paramType == "HOTP" ? "image://theme/icon-m-enter-next" : "image://theme/icon-m-enter-accept"
|
||||
EnterKey.onClicked: paramType == "HOTP" ? otpCounter.focus = true : addOTP.accept()
|
||||
}
|
||||
TextField {
|
||||
id: otpCounter
|
||||
|
@ -137,7 +138,7 @@ Dialog {
|
|||
}
|
||||
|
||||
// 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
|
||||
onDone: {
|
||||
|
|
|
@ -69,20 +69,13 @@ Page {
|
|||
// get seconds from current Date
|
||||
var curDate = new Date();
|
||||
var seconds = curDate.getSeconds();
|
||||
var type;
|
||||
|
||||
// Iterate over all List entries
|
||||
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)
|
||||
if (appWin.listModel.get(i).otp == "------" || seconds == 30 || seconds == 0 || (curDate.getTime() - lastUpdated > 2000)) {
|
||||
if (appWin.listModel.get(i).title.substr(0,6) == "Steam:") {
|
||||
type = "TOTP_STEAM"
|
||||
} else {
|
||||
type = "TOTP"
|
||||
}
|
||||
|
||||
var curOTP = OTP.calcOTP(appWin.listModel.get(i).secret, type)
|
||||
var curOTP = OTP.calcOTP(appWin.listModel.get(i).secret, appWin.listModel.get(i).type)
|
||||
appWin.listModel.setProperty(i, "otp", curOTP);
|
||||
}
|
||||
} else if (appWin.coverType == "HOTP" && (curDate.getTime() - lastUpdated > 2000) && appWin.listModel.get(i).fav == 1) {
|
||||
|
|
Loading…
Reference in a new issue