using System; using System.Runtime.InteropServices; using Lithnet.CredentialProvider.Interop; namespace Lithnet.CredentialProvider { /// /// A masked password text box, with a Password property that provides the password in plain text /// public class InsecurePasswordTextboxControl : ControlBase { private string password; /// /// Creates a new control. /// /// The unique key for this control public InsecurePasswordTextboxControl(string key) : this(key, null) { } /// /// Creates a new control. /// /// The unique key for this control /// The label associated with the control public InsecurePasswordTextboxControl(string key, string label) : base(key, label, FieldType.PasswordText) { } private InsecurePasswordTextboxControl(InsecurePasswordTextboxControl source) : base(source) { } /// /// Gets or sets the password value in plain text /// public string Password { get { return this.password; } set { if (this.password != value) { this.password = value; if (this.password?.Length > 0) { var ptr = Marshal.StringToCoTaskMemUni(this.password); this.logger.LogWarningDebug($"0x:{ptr.ToString("X16")} - Created ptr for outgoing SetFieldString"); this.Events?.SetFieldString(this.Credential, this.Id, ptr); } else { this.Events?.SetFieldString(this.Credential, this.Id, IntPtr.Zero); } this.RaisePropertyChanged(nameof(this.Password)); } } } internal void SetPasswordInternal(string s) { this.password = s; this.RaisePropertyChanged(nameof(this.Password)); } internal override ControlBase Clone() { var clone = new InsecurePasswordTextboxControl(this); clone.password = this.password; return clone; } } }