Skip to main content
All docs
V23.2

Login Form

  • 2 minutes to read

The Login Form (LoginForm) is a sign-in form that accepts user email and password information.

Login Form - WinForms UI Templates

What’s Inside

The Login Form includes the following UI components that ship as part of the DevExpress UI Templates:

Show Login Form

using DevExpress.UITemplates.Collection.Forms;

// ...
static void Main() {
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    using(var frm = new LoginForm()) {
        if(frm.ShowDialog() == DialogResult.OK) {
            if(frm.IsAuthorizationComplete) {
                Application.Run(new Form1());
            }
        }
    }
}

Use the following properties of the form’s ViewModel to personalize its title, button, and links:

  • Title - the form’s title.
  • Action - the Login button’s caption.
  • RegisterLink - the Register link’s text.
  • RecoveryLink - the Recover Password link’s text.
public partial class Login : HtmlFormBase {
    // ...
    public class ViewModel {
        public string Title {
            get { return "Log In"; }
        }
        public string Action {
            get { return "Log In"; }
        }
        public string RecoveryLink {
            get { return "Forgot the password?"; }
        }
        public string RegisterLink {
            get { return "Create an account"; }
        }
        // ...
    }
}

Form State and Actions

Use the form’s Status property to obtain its state.

Value Description
AuthorizationComplete Login/email authentication succeeded.
AuthorizationFailed Login/email authentication failed.
RecoveryRequested The ‘Forgot the password?’ link has been clicked.
RegistrationRequested The ‘Create an account’ link has been clicked.
Unknown

Use the following methods of the ViewModel to implement the form actions, which include user credentials authentication, user/account registration, and password recovery.

  • QueryAuthorization - authenticates user credentials.
  • Recover - requests a password reset and closes the form.
  • Register - registers a new user/account and closes the form.
public partial class Login : HtmlFormBase {
    // ...
    public class ViewModel {
        public virtual string Email { get; set; }
        public virtual string Password { get; set; }

        public virtual Status Status {
            get;
            protected set;
        }
        public void Recover() {
            Status = Status.RecoveryRequested;
            /* Implement password recovery. */
            CloseWindow();
        }
        public void Register() {
            Status = Status.RegistrationRequested;
            /* Register a new account. */
            CloseWindow();
        }
        public void LogIn() {
            Status = QueryAuthorization() ? Status.AuthorizationComplete : Status.AuthorizationFailed;
        }
        bool QueryAuthorization() {
            /* 
               Authenticate the user credentials.
               Return 'false' if login/email authentication failed.
            */
            return true;
        }
    }
}