Exemple #1
0
 public void Loadpublic(NativeMethods.CREDENTIAL credential)
 {
     Username = credential.UserName;
     if (credential.CredentialBlobSize > 0)
     {
         Password = Marshal.PtrToStringUni(credential.CredentialBlob, credential.CredentialBlobSize / 2);
     }
     Target           = credential.TargetName;
     Type             = (CredentialType)credential.Type;
     PersistanceType  = (PersistanceType)credential.Persist;
     Description      = credential.Comment;
     LastWriteTimeUtc = DateTime.FromFileTimeUtc(credential.LastWritten);
 }
Exemple #2
0
 public bool Save()
 {
     CheckNotDisposed();
     _unmanagedCodePermission.Demand();
     byte[] bytes = Encoding.Unicode.GetBytes(Password);
     if (Password.Length > 512)
     {
         throw new ArgumentOutOfRangeException("The password has exceeded 512 bytes.");
     }
     NativeMethods.CREDENTIAL userCredential = default(NativeMethods.CREDENTIAL);
     userCredential.TargetName         = Target;
     userCredential.UserName           = Username;
     userCredential.CredentialBlob     = Marshal.StringToCoTaskMemUni(Password);
     userCredential.CredentialBlobSize = bytes.Length;
     userCredential.Comment            = Description;
     userCredential.Type    = (int)Type;
     userCredential.Persist = (int)PersistanceType;
     if (!NativeMethods.CredWrite(ref userCredential, 0u))
     {
         return(false);
     }
     LastWriteTimeUtc = DateTime.UtcNow;
     return(true);
 }
 public static extern bool CredWrite([In] ref NativeMethods.CREDENTIAL userCredential, [In] uint flags);