private void btnAdd_Click(object sender, EventArgs e) { formServerInformation serverDlg = new formServerInformation(); Server server = new Server(); serverDlg.Server = server; if (serverDlg.ShowDialog() == DialogResult.OK) { userSettings.ServerConnections.List.Add(server); LoadSettings(); } }
public static bool Authenticate(hMailServer.Application app, Settings.Server server) { string password = server.encryptedPassword; if (password.Length > 0) { password = Encryption.Decrypt(password); } bool wrongPassword = false; while (true) { if (!server.savePassword || wrongPassword) { // The user must input the password. formEnterPassword dlg = new formEnterPassword(); if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) { return(false); } password = dlg.Password; } try { hMailServer.Account account = app.Authenticate(server.userName, password); if (account == null) { // Wrong password, try again. MessageBox.Show("The specified user name or password is incorrect.", EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK); wrongPassword = true; } else { try { if (account.AdminLevel != eAdminLevel.hAdminLevelServerAdmin) { // Wrong password, try again. MessageBox.Show("hMailServer server administration rights are required to run hMailServer Administrator.", EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } return(true); } finally { Marshal.ReleaseComObject(account); } } } catch (Exception e) { // Wrong password, try again. MessageBox.Show("The specified user name or password is incorrect." + Environment.NewLine + e.Message, EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK); wrongPassword = true; } } }
private static UserSettings CreateDefault() { UserSettings retVal = new UserSettings(); Server server = new Server(); server.hostName = "localhost"; server.userName = "******"; server.encryptedPassword = ""; retVal.ServerConnections.List.Add(server); return retVal; }
private bool Connect(Server server) { try { application = APICreator.Create(server.hostName); if (application == null) return false; if (application.Database.RequiresUpgrade) { string message = string.Format("Your database is not up to date and needs to be upgraded." + Environment.NewLine + "Please run DBUpdater.exe to update the datatabase." + Environment.NewLine + Environment.NewLine + "Current database version: {0}" + Environment.NewLine + "Required database version: {1}", application.Database.CurrentVersion, application.Database.RequiredVersion); MessageBox.Show(message, EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } if (APICreator.Authenticate(application, server)) { DialogResult = DialogResult.OK; _serverName = server.hostName; return true; } return false; } catch (Exception ex) { MessageBox.Show(ex.Message, EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } }