dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlConnection Class / AuthenticationPrompt Event
Example

In This Topic
    AuthenticationPrompt Event
    In This Topic
    The event occurs when performing keyboard-interactive authentication.
    Syntax
    'Declaration
     
    Public Event AuthenticationPrompt As MySqlAuthenticationPromptHandler
    public event MySqlAuthenticationPromptHandler AuthenticationPrompt
    Event Data

    The event handler receives an argument of type MySqlAuthenticationPrompEventArgs containing data related to this event. The following MySqlAuthenticationPrompEventArgs properties provide information specific to this event.

    PropertyDescription
    Gets the authentication instruction and additional information about authentication.  
    Gets the name of the authentication method.  
    Gets an array of prompts for the fields, that should be filled in the Responses array.  
    Gets the array of strings, which should be filled in the MySqlConnection.AuthenticationPrompt event handler according to the Prompts array. Each Responds string corresponds to the Prompts string.  
    Remarks
    Clients that want to process authentication requests sent by the server should create a MySqlAuthenticationPromptHandler delegate to listen to this event. This event may be called several times during authentication process to request corresponding user information. The server sends a request concerning information that should be obtained from the user. The amount of requested information can be learned by defining the length of the Prompts array. Developer should provide an interface for the user to enter requested information. The received information should be written to the Responses array.
    Example
    This sample shows how performing keyboard-interactive authentication.
    static void Main(string[] args) {
            MySqlConnection connection = new MySqlConnection("host=mysql_host;port=3306;user id=mysql_user;password=mysql_password;");
            connection.Protocol = MySqlProtocol.Ssh;
            // sets ssh options
            connection.SshOptions.Host = "ssh_host";
            connection.SshOptions.Port = 22;
            connection.SshOptions.User = "ssh_user";
            connection.SshOptions.AuthenticationType = SshAuthenticationType.KeyboardInteractive;
            // Associate the AuthenticationPrompt event with your event handle
            connection.AuthenticationPrompt += new MySqlAuthenticationPromptHandler(connection_AuthenticationPrompt);
    
            connection.Open();
            Console.WriteLine(connection.State);
    
            connection.Close();
            Console.ReadKey();
    }
    
    static void connection_AuthenticationPrompt(object sender, MySqlAuthenticationPrompEventArgs e) {
    
            for (int i = 0; i < e.Prompts.Length; i++) {
                    if (e.Prompts[i].Contains("Password"))
                            e.Responses[i] = "111111";
                    else
                            if (e.Prompts[i].Contains("UserId"))
                            e.Responses[i] = "testUserId";
            }
    }
    Sub Main()
            Dim connection As MySqlConnection = New MySqlConnection("host=mysql_host;port=3306;user id=mysql_user;password=mysql_password;")
            connection.Protocol = MySqlProtocol.Ssh
            ' sets ssh options
            connection.SshOptions.Host = "ssh_host"
            connection.SshOptions.Port = 22
            connection.SshOptions.User = "ssh_user"
            connection.SshOptions.AuthenticationType = SshAuthenticationType.KeyboardInteractive
            ' Associate the AuthenticationPrompt event with your event handle
            AddHandler connection.AuthenticationPrompt, AddressOf connection_AuthenticationPrompt
    
            connection.Open()
            Console.WriteLine(connection.State.ToString)
    
            connection.Close()
            Console.ReadKey()
    End Sub
    
    Sub connection_AuthenticationPrompt(ByVal sender As Object, ByVal e As MySqlAuthenticationPrompEventArgs)
    
            For i As Integer = 0 To e.Prompts.Length - 1
                    If e.Prompts(i).Contains("Password") Then
                            e.Responses(i) = "111111"
                    ElseIf e.Prompts(i).Contains("UserId") Then
                            e.Responses(i) = "testUserId"
                    End If
            Next
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also