Korathu Alexander

Korathu Alexander

  • 1.4k
  • 349
  • 37k

Windows Credential Manager with c#

May 18 2018 3:10 AM
I am saving the  credentails to the windows vault store using the credential manager API . But i need to keep it secure and also what is the maximum  password limit length to do so.
 
Core Code to save and retrieve the credentails in the windows vault folder as below:
  1. //save password to the windows vault store using Credential Manager  
  2. public void SavePassword(string password)  
  3. {  
  4. try  
  5. {  
  6. using (var cred = new Credential())  
  7. {  
  8. cred.Password = password;  
  9. cred.Target = PasswordName;  
  10. cred.Type = CredentialType.Generic;  
  11. cred.PersistanceType = PersistanceType.LocalComputer;  
  12. cred.Save();  
  13. }  
  14. }  
  15. catch(Exception ex)  
  16. {  
  17. }  
  18. }  
  19. //retrieve password from the windows vault store using Credential Manager   
  20. public string GetPassword()  
  21. {  
  22. try {  
  23. using (var cred = new Credential())  
  24. {  
  25. cred.Target = PasswordName;  
  26. cred.Load();  
  27. return cred.Password;  
  28. }  
  29. }  
  30. catch (Exception ex)  
  31. {  
  32. }  
  33. return "";  
  34. } 

Answers (3)