I'm working on a login process for a WinForms application and was checking various options to store my app login credentials and have faced an issue on which I would like to have some help.
My idea is to store the app credentials to the Windows Credential Manager if the OS supports it (target OS can be anything from Vista to Win10) else store it to the Windows Registry. However the issue I am facing is that how will I check that OS supports Windows Credential Manager, I read somewhere that it will throw an error if it doesn't exists but is there a better method where I can check that without handling it in the exception.
I am using CredentialManagement Nuget package to access the Windows Credential Manager functionalities.
public static string GetPassword()
{
try
{
using (var cred = new Credential())
{
cred.Target = CredentialName;
if (cred.Exists())
{
cred.Load();
return cred.Password;
}
else
{
return string.Empty;
}
}
}
catch (Exception ex)
{
// Handle the exception
}
}