private bool Login() { using (CredentialsDialog dlgLogin = new CredentialsDialog()) { dlgLogin.User = Config.Get <string>("LastUser", string.Empty); dlgLogin.Caption = "CCOW Server"; dlgLogin.Message = "Please provide an administrative user to access configuration settings."; while (true) { if (dlgLogin.ShowDialog() == DialogResult.OK) { IntPtr token = IntPtr.Zero; if (AuthenticationUtils.Login(dlgLogin.Domain, dlgLogin.User, dlgLogin.PasswordToString(), out token)) { WindowsPrincipal principal = Thread.CurrentPrincipal as WindowsPrincipal; if (AuthenticationUtils.IsAdmin(principal) || AuthenticationUtils.IsDomainAdmin(principal)) { string saveUser = dlgLogin.User; if (!string.IsNullOrEmpty(dlgLogin.Domain)) { saveUser = dlgLogin.Domain + "\\" + dlgLogin.User; } Config.Set <string>("LastUser", saveUser); return(true); } else { MessageBox.Show(this, "User is not a member of Administrators group.", "Invalid User", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { Win32Exception e = new Win32Exception(Marshal.GetLastWin32Error()); MessageBox.Show(this, e.Message, "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { break; } } } return(false); }