protected void uxLogin_Click(object sender, EventArgs e)
    {
        /*
         * The system against which the user will be authenticated.
         */
        var AuthenticationSystem = new AuthenticationClass();

        /*
         * Attempt to authenticate the user using third-party system.
         */
        bool authenticated = AuthenticationSystem.Authenticate(uxUsername.Text, uxPassword.Text);

        if (authenticated)
        {
            /*
             * The class used to login/create Ektron proxy users.
             */
            var EktronProxyUserManager = new ThirdPartyUserManagement();

            /*
             * Attempt login.
             */
            bool ektronLoginSuccess = EktronProxyUserManager.AttemptProxyUserLogin(AuthenticationSystem.AuthenticationSystemId, uxUsername.Text);

            /*
             * If login attempt failed...
             */
            if (!ektronLoginSuccess)
            {
                /*
                 * Create new user from auth system.
                 *
                 * You may want to have the user complete a more robust profile before this step.
                 * I simply chose the path of least resistance here to illustrate one of several
                 * possible scenarios.
                 */
                bool ektronUserCreated = EktronProxyUserManager.CreateEktronProxyUser(AuthenticationSystem.AuthenticationSystemId, uxUsername.Text);

                /*
                 * If we were able to create the user...
                 */
                if (ektronUserCreated)
                {
                    /*
                     * Attempt to login the newly created user.
                     */
                    ektronLoginSuccess = EktronProxyUserManager.AttemptProxyUserLogin(AuthenticationSystem.AuthenticationSystemId, uxUsername.Text);
                }
            }

            if (ektronLoginSuccess)
            {
                /*
                 * Redirect to ensure the cookie is properly set and to clear any postback data.
                 */
                Response.Redirect(Request.RawUrl);
            }
            else
            {
                // show error message
            }
        }
    }