Skip to content

Commit

Permalink
Update password from String to SecureString
Browse files Browse the repository at this point in the history
  • Loading branch information
YanaXu committed Dec 12, 2024
1 parent a3d676b commit 3e5fdfa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public class PSContainerRegistryCredential
public PSContainerRegistryCredential(RegistryListCredentialsResult credentials)
{
Username = credentials?.Username;
Password = credentials?.Password?.Length > 0 ? credentials.Password[0]?.Value : string.Empty;
Password2 = credentials?.Password?.Length > 1 ? credentials.Password[1]?.Value : string.Empty;
Password = credentials?.Password?.Length > 0 ? credentials.Password[0]?.Value.ToSecureString() : string.Empty.ToSecureString();
Password2 = credentials?.Password?.Length > 1 ? credentials.Password[1]?.Value.ToSecureString() : string.Empty.ToSecureString();
}

public string Username { get; set; }
public string Password { get; set; }
public string Password2 { get; set; }
public System.Security.SecureString Password { get ; set; }
public System.Security.SecureString Password2 { get ; set; }
}
}
19 changes: 19 additions & 0 deletions src/ContainerRegistry/ContainerRegistry.Autorest/custom/Utils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Microsoft.Azure.PowerShell.Cmdlets.ContainerRegistry.Models.Api202301Preview
{
public static class Utils
{
public static System.Security.SecureString ToSecureString(this string input)
{
if (string.IsNullOrEmpty(input))
return null;

System.Security.SecureString secureString = new System.Security.SecureString();
foreach (char c in input)
{
secureString.AppendChar(c);
}
secureString.MakeReadOnly();
return secureString;
}
}
}

0 comments on commit 3e5fdfa

Please sign in to comment.