Authentication

Topics: CAB & Smart Client Software Factory
Apr 11, 2006 at 11:50 AM
originally posted by: aaguiarz

I want to authenticate a user using the Membership API.

The IAuthenticationService is called to set the Thread/AppDomain principal.

If I display a dialog and call the membership API inside my IAuthenticationService, then I don't know what to do when the user/password is wrong, or when the user presses 'Cancel', as I cannot return a value specifying if the user was correctly authenticated or not.

How /where should I display a login box in this scenario?

Thanks

Andres
Apr 11, 2006 at 12:27 PM
originally posted by: MarcoPaul

You need to use Environment.Exit(0) if authentication fails.
Apr 11, 2006 at 1:29 PM
originally posted by: ChrisHolmes

You can display the dialog when you implement the Authenticate() method of the IAuthenticateService interface.

Like so:

public class AuthenticationService : IAuthenticationService
{
public void Authenticate()
{
LoginView view = new LoginView();
view.StartPosition = FormStartPosition.CenterScreen;
view.ShowDialog();
if(view.DialogResult != DialogResult.OK)
{
Environment.Exit(0);
}
}
}

Then in your LoginView class you can access the Membership API (or any backend database, whatever) and perform your authentication.