Share via


ICredentialBuilder.SetCredentials Method

Definition

Creates a CredentialInfo object.

Overloads

SetCredentials(IServiceProvider, Boolean)

Creates a CredentialInfo object that contains the user name and password.

SetCredentials(IServiceProvider, Boolean, EventHandler)

Creates a CredentialInfo object that contains the user name and password and uses the specified event-handler delegate for a Help dialog box.

SetCredentials(IServiceProvider, Boolean)

Creates a CredentialInfo object that contains the user name and password.

public:
 Microsoft::Web::Management::Client::CredentialInfo ^ SetCredentials(IServiceProvider ^ serviceProvider, bool verifyValidWindowsUserPassword);
public Microsoft.Web.Management.Client.CredentialInfo SetCredentials (IServiceProvider serviceProvider, bool verifyValidWindowsUserPassword);
abstract member SetCredentials : IServiceProvider * bool -> Microsoft.Web.Management.Client.CredentialInfo
Public Function SetCredentials (serviceProvider As IServiceProvider, verifyValidWindowsUserPassword As Boolean) As CredentialInfo

Parameters

serviceProvider
IServiceProvider

A IServiceProvider interface that represents the service provider for gathering user credentials.

verifyValidWindowsUserPassword
Boolean

true if the password should be verified for Windows; otherwise, false.

Returns

A CredentialInfo object that contains the user name and password.

Examples

The following example implements this method.

public CredentialInfo SetCredentials(IServiceProvider serviceProvider,
bool verifyPW) {
    return this.SetCredentials(serviceProvider,
        verifyPW, null);
}

public CredentialInfo SetCredentials(IServiceProvider serviceProvider,
    bool verifyPW, EventHandler showHelp) {
    if (serviceProvider == null) {
        throw new ArgumentNullException("serviceProvider");
    }

    IManagementUIService uiService = (IManagementUIService)serviceProvider.
        GetService(typeof(IManagementUIService));
    Debug.Assert(uiService != null);

    CredentialInfo credentials = null;

    using (SetCredoDlg dialog =
        new SetCredoDlg(serviceProvider, showHelp)) {
        dialog.VerifyValidWindowsUserPassword = verifyPW;

        if (uiService.ShowDialog(dialog) == DialogResult.OK) {
            credentials = new CredentialInfo();
            credentials.UserName = dialog.UserName;
            credentials.Password = dialog.Password;
        }
    }

    return credentials;
} 

Applies to

SetCredentials(IServiceProvider, Boolean, EventHandler)

Creates a CredentialInfo object that contains the user name and password and uses the specified event-handler delegate for a Help dialog box.

public:
 Microsoft::Web::Management::Client::CredentialInfo ^ SetCredentials(IServiceProvider ^ serviceProvider, bool verifyValidWindowsUserPassword, EventHandler ^ showHelp);
public Microsoft.Web.Management.Client.CredentialInfo SetCredentials (IServiceProvider serviceProvider, bool verifyValidWindowsUserPassword, EventHandler showHelp);
abstract member SetCredentials : IServiceProvider * bool * EventHandler -> Microsoft.Web.Management.Client.CredentialInfo
Public Function SetCredentials (serviceProvider As IServiceProvider, verifyValidWindowsUserPassword As Boolean, showHelp As EventHandler) As CredentialInfo

Parameters

serviceProvider
IServiceProvider

A IServiceProvider interface that represents the service provider for gathering user credentials.

verifyValidWindowsUserPassword
Boolean

true if the password should be verified for Windows; otherwise, false.

showHelp
EventHandler

A EventHandler delegate for displaying a Help dialog box.

Returns

A CredentialInfo object that contains the user name and password.

Examples

The following example implements this method.

public CredentialInfo SetCredentials(IServiceProvider serviceProvider,
bool verifyPW) {
    return this.SetCredentials(serviceProvider,
        verifyPW, null);
}

public CredentialInfo SetCredentials(IServiceProvider serviceProvider,
    bool verifyPW, EventHandler showHelp) {
    if (serviceProvider == null) {
        throw new ArgumentNullException("serviceProvider");
    }

    IManagementUIService uiService = (IManagementUIService)serviceProvider.
        GetService(typeof(IManagementUIService));
    Debug.Assert(uiService != null);

    CredentialInfo credentials = null;

    using (SetCredoDlg dialog =
        new SetCredoDlg(serviceProvider, showHelp)) {
        dialog.VerifyValidWindowsUserPassword = verifyPW;

        if (uiService.ShowDialog(dialog) == DialogResult.OK) {
            credentials = new CredentialInfo();
            credentials.UserName = dialog.UserName;
            credentials.Password = dialog.Password;
        }
    }

    return credentials;
} 

Applies to