void otpCopyToolStripItem_Click(object sender, EventArgs e) { PwEntry entry; if (this.GetSelectedSingleEntry(out entry)) { OtpAuthData data = OtpAuthUtils.loadData(entry); if (data == null) { if (MessageBox.Show("Must configure TOTP on this entry. Do you want to do this now?", "Not Configured", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ShowOneTimePasswords form = new ShowOneTimePasswords(entry, host); form.ShowDialog(); } } else { var totp = new Totp(data.Key, step: data.Step, mode: data.OtpHashMode, totpSize: data.Size); var text = totp.ComputeTotp().ToString().PadLeft(data.Size, '0'); if (ClipboardUtil.CopyAndMinimize(new KeePassLib.Security.ProtectedString(true, text), true, this.host.MainWindow, entry, this.host.Database)) { this.host.MainWindow.StartClipboardCountdown(); } } } }
private void otpDialogToolStripItem_Click(object sender, EventArgs e) { PwEntry entry; if (GetSelectedSingleEntry(out entry)) { ShowOneTimePasswords form = new ShowOneTimePasswords(entry, host); form.ShowDialog(); } }
private void otpCopyToolStripItem_Click(object sender, EventArgs e) { PwEntry entry; if (this.GetSelectedSingleEntry(out entry)) { OtpAuthData data = OtpAuthUtils.loadData(entry); if (data == null) { if (MessageBox.Show(KeeOtp2Statics.MessageBoxOtpNotConfigured, KeeOtp2Statics.PluginName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ShowOneTimePasswords form = new ShowOneTimePasswords(entry, host); form.ShowDialog(); } } else { OtpBase otp = OtpAuthUtils.getOtp(data); if (data.Type == OtpType.Totp) { if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, otp.getTotpString(OtpTime.getTime())), true, this.host.MainWindow, entry, this.host.Database)) { this.host.MainWindow.StartClipboardCountdown(); } } else if (data.Type == OtpType.Hotp) { if (ClipboardUtil.CopyAndMinimize(new ProtectedString(true, otp.getHotpString(data.Counter)), true, this.host.MainWindow, entry, this.host.Database)) { this.host.MainWindow.StartClipboardCountdown(); } OtpAuthUtils.increaseHotpCounter(host, data, entry); } } } }