none
[E2010] [C#] [Windows]: How can I login to EWS using WebCredentials with a SecureString?

    Question

  • Hi,

    For EWS I need to allow users to specify username/password to login in certain edge cases (when the default does not work). Hence using the Credentials property, see below:

    service.Credentials = new WebCredentials(username, password);

    The problem is that this password is a regular .NET String and is thus unsecure. I cannot find a WebCredentials version that takes a SecureString as input. Using NetworkCredentials instead does indeed take a SecureString but it is much slower (unacceptably slow) compared to WebCredentials so I cannot use it.

    Do you have any tips how to use WebCredentials with a SecureString? Or any other ideas?

    Many thanks.
    Sunday, February 26, 2017 6:54 PM

All replies

  • Hi,

    For EWS I need to allow users to specify username/password to login in certain edge cases (when the default does not work). Hence using the Credentials property, see below:

    service.Credentials = new WebCredentials(username, password);

    The problem is that this password is a regular .NET String and is thus unsecure. I cannot find a WebCredentials version that takes a SecureString as input. Using NetworkCredentials instead does indeed take a SecureString but it is much slower (unacceptably slow) compared to WebCredentials so I cannot use it.

    Do you have any tips how to use WebCredentials with a SecureString? Or any other ideas?

    Many thanks.

    Did you try this method ?

    string Username = @"Domain\UserName";
    string Password = "Password@12";
    SecureString ssPassword = new SecureString();
    foreach (char x in Password)
    ssPassword.AppendChar(x);
    service.Credentials = new WebCredentials(Username,ssPassword);

    Pavan Maganti ~ ( Exchange | 2003/2007/2010/E15(2013)) ~~ Please remember to click “Vote As Helpful" if it really helps and "Mark as Answer” if it answers your question, “Unmark as Answer” if a marked post does not actually answer your question. ~~ This Information is provided is "AS IS" and confers NO Rights!!


    • Edited by PK M Wednesday, March 8, 2017 2:35 PM
    • Proposed as answer by PK M Monday, March 13, 2017 9:40 AM
    Wednesday, March 8, 2017 2:34 PM
  • I do not find a WebCredentials constructor that takes a SecureString as argument, do you?

    https://msdn.microsoft.com/en-us/library/office/dd635792(v=exchg.80).aspx

    Monday, March 13, 2017 10:03 PM
  • I do not find a WebCredentials constructor that takes a SecureString as argument, do you?

    https://msdn.microsoft.com/en-us/library/office/dd635792(v=exchg.80).aspx

    SecureString Constructor ()

    Pavan Maganti ~ ( Exchange | 2003/2007/2010/E15(2013)) ~~ Please remember to click “Vote As Helpful" if it really helps and "Mark as Answer” if it answers your question, “Unmark as Answer” if a marked post does not actually answer your question. ~~ This Information is provided is "AS IS" and confers NO Rights!!

    Tuesday, March 14, 2017 12:38 PM
  • Is this a joke?
    Wednesday, March 15, 2017 6:05 PM
  • Hey, it's an old post but did you find the solution?
    Monday, February 26, 2018 3:32 PM
  • I used this:

    service.Credentials = new WebCredentials(new System.Net.NetworkCredential(name, password, domain)) ;

    • Proposed as answer by Sepp Secrets Wednesday, July 4, 2018 1:48 PM
    Wednesday, July 4, 2018 1:46 PM