Step 5. Displaying a Login Window

When you create a new Windows Presentation Foundation application, a Login window is automatically created for you. By default, it's a simple window with just a few controls, but you can enhance it to your heart's content:

To display a login window at application startup, follow these steps:

  1. In the Solution Explorer, double-click your MainEntry.cs or MainEntry.vb file to open it in the code Window and uncomment the following code.

    In C#:

    //// Display the Login Window
    //UserLoginWindow LoginWindow = new UserLoginWindow();
    //Result = LoginWindow.ShowDialog();

    And in VB .NET:

    '''' Uncomment this code to display the login window
    ''Dim LoginWindow As UserLoginWindow = New UserLoginWindow()
    ''Result = LoginWindow.ShowDialog()

  2. If you are using server authentication to access your security database (which requires a user id and password), you need to specify an initial user ID and password for connecting to this database when first authenticating a user. Note that these values are only used on the initial connection to authenticate the user.

    To specify these user ID and password values:

    • In the Solution Explorer, right-click the UserLoginWindow and select View Code from the shortcut menu.

    • Set the UserIDConnect and PasswordConnect properties in the constructor of the Login window.

      In C#:

      public UserLoginWindow()
      {
      	InitializeComponent();
      
      	this.UserIDConnect = "sa";
      	this.PasswordConnect = "";
      
      	this.FocusOnLoadElement = this.txtUserId;
      }

      And in VB .NET:

      Public Sub New()
      
            InitializeComponent()
      	
      	Me.UserIDConnect = "sa"
      	Me.PasswordConnect = ""
      
      End Sub

    Even though these code samples hard code the initial user authentication connection information at design time, you can data drive these settings, storing them in an external file and setting them dynamically at run time.

Using the HookUserAuthenticated Method

At times you may want to perform additional processing when a user has been authenticated. The HookUserAuthenticated method provides a hook into which you can place code to be executed after a user's login credentials (such as user ID and password) are authenticated. You can add an override of this method to your application-level login form and place processing code in this method.

For example, in C#:

public override void HookUserAuthenticated(object userPK)
{
	// TODO: Additional processing code
}

And in VB .NET:

Public Overrides Sub HookUserAuthenticated(userPK As Object)
	' TODO: Additional processing code
End Sub

See also:
Step 5. Displaying a Users Window


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/26/18
Comment or report problem with topic