From f11d3874bb27e96208ced5260be5ec0a90f69c35 Mon Sep 17 00:00:00 2001 From: Dag Heyman Date: Fri, 17 Feb 2017 10:14:37 +0100 Subject: [PATCH] Add cooldown period for HOTP creds --- qml/Main.qml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/qml/Main.qml b/qml/Main.qml index 66b1f9aa..e6cd3660 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -17,6 +17,7 @@ ApplicationWindow { property var credentials: device.credentials property bool validated: device.validated property bool hasDevice: device.hasDevice + property var cooldowns: [] PasswordPrompt { id: passwordPrompt @@ -34,7 +35,6 @@ ApplicationWindow { onCredentialsChanged: { updateExpiration() touchYourYubikey.close() - console.log('CREDENTIALS ', JSON.stringify(credentials)) } SystemPalette { @@ -167,9 +167,18 @@ ApplicationWindow { visible: repeater.selected != null && (repeater.selected.oath_type === "hotp" || repeater.selected.touch === true) + enabled: repeater.selected != null && !isInCoolDown(repeater.selected.name) text: qsTr('Generate code') shortcut: "Space" - onTriggered: calculateCredential(repeater.selected) + onTriggered: { + if (!isInCoolDown(repeater.selected.name)) { + calculateCredential(repeater.selected) + if (repeater.selected.oath_type === "hotp") { + cooldowns.push(repeater.selected.name) + coolDownTimer.restart() + } + } + } } MenuItem { text: qsTr('Delete') @@ -178,6 +187,12 @@ ApplicationWindow { } } + Timer { + id: coolDownTimer + interval: 5000 + onTriggered: cooldowns = [] + } + Item { id: arrowKeys focus: true @@ -298,6 +313,7 @@ ApplicationWindow { font.pointSize: 13 } Text { + opacity: isInCoolDown(modelData.name) ? 0.6 : 1 visible: modelData.code != null text: qsTr('') + modelData.code font.family: "Verdana" @@ -416,6 +432,9 @@ ApplicationWindow { return result } + function isInCoolDown(name) { + return cooldowns.indexOf(name) !== -1 + } function hasIssuer(name) { return name.indexOf(':') !== -1 }