private void OnOTPQRCode(object sender, EventArgs e) { if (m_host.MainWindow.GetSelectedEntriesCount() != 1) { return; } KPOTP otp = OTPDAO.GetOTP(m_host.MainWindow.GetSelectedEntry(true)); if (!otp.Valid) { return; } try { ZXing.BarcodeWriter zBW = new ZXing.BarcodeWriter(); zBW.Options.Height = 320; zBW.Options.Width = 320; zBW.Format = ZXing.BarcodeFormat.QR_CODE; Bitmap bmp = zBW.Write(otp.OTPAuthString.ReadString()); QRForm f = new QRForm(); f.FormBorderStyle = FormBorderStyle.FixedDialog; f.StartPosition = FormStartPosition.CenterParent; f.Text = PluginTranslate.PluginName; f.MinimizeBox = false; f.MaximizeBox = false; PictureBox pb = new PictureBox(); pb.Location = new Point(0, 0); pb.Image = new Bitmap(bmp, bmp.Size); //Assigning bmp directly did not work in my Ubuntu VM... pb.ClientSize = pb.Image.Size; f.ClientSize = pb.Size; f.Controls.Add(pb); if (!string.IsNullOrEmpty(otp.Issuer) && (otp.Issuer != PluginTranslate.PluginName)) { Label lIssuer = new Label(); lIssuer.Width = f.ClientSize.Width; lIssuer.Text = otp.Issuer; lIssuer.Location = new Point(0, f.ClientSize.Height + 10); f.Controls.Add(lIssuer); f.Height += lIssuer.Height + 10; } if (!string.IsNullOrEmpty(otp.Label)) { Label lLabel = new Label(); lLabel.Width = f.ClientSize.Width; lLabel.Text = otp.Label; lLabel.Location = new Point(0, f.ClientSize.Height + 10); f.Controls.Add(lLabel); f.Height += lLabel.Height + 10; } f.Height += 5; Timer tClose = new Timer(); tClose.Interval = 30000; tClose.Tick += (o, e1) => { tClose.Stop(); tClose.Dispose(); if (f != null) { f.Close(); } }; f.Shown += (o, e2) => { KeePass.UI.GlobalWindowManager.AddWindow(f, f); tClose.Start(); }; f.FormClosed += (o, e1) => { if (f != null) { KeePass.UI.GlobalWindowManager.RemoveWindow(f); } }; f.ShowDialog(KeePass.UI.GlobalWindowManager.TopWindow); pb.Image.Dispose(); f.Dispose(); bmp.Dispose(); } catch { }; }
private void OnOTPQRCode(object sender, EventArgs e) { if (m_host.MainWindow.GetSelectedEntriesCount() != 1) { return; } KPOTP otp = OTPDAO.GetOTP(m_host.MainWindow.GetSelectedEntry(true)); if (!otp.Valid) { return; } try { byte[] bOTP = otp.OTPAuthString.ReadUtf8(); QRCoder.QRCodeData qrd = QRCoder.QRCodeGenerator.GenerateQrCode(bOTP, QRCoder.QRCodeGenerator.ECCLevel.Q); MemUtil.ZeroByteArray(bOTP); QRCoder.QRCode qrc = new QRCoder.QRCode(qrd); Bitmap bmp = qrc.GetGraphic(8); QRForm f = new QRForm(); f.FormBorderStyle = FormBorderStyle.FixedDialog; f.StartPosition = FormStartPosition.CenterParent; f.Text = PluginTranslate.PluginName; f.MinimizeBox = false; f.MaximizeBox = false; PictureBox pb = new PictureBox(); pb.Size = new Size(bmp.Width, bmp.Height); pb.Location = new Point(0, 0); f.ClientSize = pb.Size; pb.Image = bmp; f.Controls.Add(pb); if (!string.IsNullOrEmpty(otp.Issuer) && (otp.Issuer != PluginTranslate.PluginName)) { Label lIssuer = new Label(); lIssuer.Width = f.ClientSize.Width; lIssuer.Text = otp.Issuer; lIssuer.Location = new Point(0, f.ClientSize.Height + 10); f.Controls.Add(lIssuer); f.Height += lIssuer.Height + 10; } if (!string.IsNullOrEmpty(otp.Label)) { Label lLabel = new Label(); lLabel.Width = f.ClientSize.Width; lLabel.Text = otp.Label; lLabel.Location = new Point(0, f.ClientSize.Height + 10); f.Controls.Add(lLabel); f.Height += lLabel.Height + 10; } f.Height += 5; Timer tClose = new Timer(); tClose.Interval = 30000; tClose.Tick += (o, e1) => { tClose.Stop(); tClose.Dispose(); if (f != null) { f.Close(); } }; f.Shown += (o, e2) => { KeePass.UI.GlobalWindowManager.AddWindow(f, f); tClose.Start(); }; f.FormClosed += (o, e1) => { if (f != null) { KeePass.UI.GlobalWindowManager.RemoveWindow(f); } }; f.ShowDialog(KeePass.UI.GlobalWindowManager.TopWindow); pb.Image.Dispose(); f.Dispose(); qrc.Dispose(); qrd.Dispose(); } catch { } }