public CreateEditForm(PwEntry entry, IPluginHost host) { _entry = entry ?? throw new ArgumentNullException(nameof(entry)); _host = host ?? throw new ArgumentNullException(nameof(host)); InitializeComponent(); this.Icon = host.MainWindow.Icon; if (entry.Strings.Exists(OtpDataUtils.Key)) { var data = entry.Strings.Get(OtpDataUtils.Key).ReadString(); if (OtpDataUtils.TryGetOtpParts(data, out var secretString, out var pinString)) { textPin.Text = pinString; textSecret.Text = secretString; } } textPin.MaxLength = Pin.MaxLength; textPin.KeyPress += TextPin_KeyPress; textSecret.CharacterCasing = CharacterCasing.Upper; textSecret.TextChanged += TextSecret_TextChanged; textSecret.KeyPress += TextSecret_KeyPress; this.AutoValidate = AutoValidate.EnableAllowFocusChange; //textPin.Validating += textPin_Validating; //textSecret.Validating += textSecret_Validating; // textPin.Validated += TextPin_Validated; textSecret.Validated += TextSecret_Validated; // }
private void SprEngine_FilterCompile(object sender, SprEventArgs e) { if (((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive) && e.Text.Contains(yaotpPlaceholder) && e.Context.Entry.Strings.Exists(OtpDataUtils.Key) && OtpDataUtils.TryParseOtpData(e.Context.Entry.Strings.Get(OtpDataUtils.Key).ReadString(), out var secret, out var pin)) { var otpString = (new Yaotp(secret, pin, () => DateTime.UtcNow)).ComputeOtp(); e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, yaotpPlaceholder, otpString); } }
private void ProcessEntry(PwEntry entry, OnSuccessDelegate onSuccess) { if (entry.Strings.Exists(OtpDataUtils.Key)) { var data = entry.Strings.Get(OtpDataUtils.Key).ReadString(); if (OtpDataUtils.TryParseOtpData(data, out var secret, out var pin) && pin.Length == secret.PinLength) { onSuccess(new Yaotp(secret, pin, () => DateTime.UtcNow)); } else { MessageBox.Show(_host.MainWindow, string.Format(Properties.Strings.Plugin_InvalidData, OtpDataUtils.Key), Properties.Strings.Plugin_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CreateEditForm_FormClosing(object sender, FormClosingEventArgs e) { if (this.DialogResult != DialogResult.OK) { return; } if (OtpDataUtils.TryCreateOtpData(textSecret.Text, textPin.Text, out var dataString)) { if (!_entry.Strings.Exists(OtpDataUtils.Key) || _entry.Strings.Get(OtpDataUtils.Key).ReadString() != dataString) { _entry.Strings.Set(OtpDataUtils.Key, new ProtectedString(true, dataString)); _entry.Touch(true); _host.MainWindow.UpdateUI(false, null, true, _host.Database.RootGroup, true, null, true); } } else { e.Cancel = true; } }