Exemple #1
0
 private void GenerateImage(string text)
 {
     if (m_image != null)
     {
         m_image.Dispose();
         m_image = null;
     }
     if (m_text != string.Empty)
     {
         using (var qg = new QRCoder.QRCodeGenerator()){
             var qr = new QRCoder.QRCode(qg.CreateQrCode(text, m_level));
             m_image = qr.GetGraphic(m_pixelsPerModule);
             Size    = m_image.Size;
             qr.Dispose();
         }
     }
 }
Exemple #2
0
        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 { }
        }