Categories
How To

How To: Use the AuthenticationDialog

Networking In The Hand 2.0 offers a new dialog which allows you to prompt the user for networking credentials. The dialog is designed for the best appearance depending on your platform, for example the screenshots below show both Windows Mobile 5.0 Pocket PC and Windows Mobile 6 Standard Landscape:-


 


   


If your application stores authentication details you can pre-populate the dialog. Optionally you can display a Save Settings checkbox on the form. The following code snippet shows how to display the dialog and return the credentials as an ICredentials object:-


private ICredentials GetCredentials(string resourceName)
{
   InTheHand.Windows.Forms.AuthenticationDialog ad = new InTheHand.Windows.Forms.AuthenticationDialog();


   ad.ResourceName = resourceName;
   if(ad.ShowDialog() == DialogResult.OK)
   {
        return new NetworkCredential(ad.Username, ad.Password, ad.Domain);
   }
   else
   {
      return null;
   }


}

By Peter Foot

Microsoft Windows Development MVP