private void MainForm_Shown(object sender, EventArgs e) { if (DateTime.Today >= DateTime.Parse("2015/01/01")) { MessageBox.Show("Please download a newer version of Kwerty Gmail Notifier at http://kwerty.com", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } Refresh(); RegistryKey registry = Registry.CurrentUser.CreateSubKey(@"Software\KwertyGmailNotifier"); string username; byte[] passwordEnc; int interval; using (registry) { username = (string)registry.GetValue("username"); passwordEnc = (byte[])registry.GetValue("password"); interval = (int)registry.GetValue("interval", 2); _newMailSound = (string)registry.GetValue("newmailsound"); } string password = null; if (passwordEnc != null) { password = UTF8Encoding.UTF8.GetString(ProtectedData.Unprotect(passwordEnc, null, DataProtectionScope.CurrentUser)); } if (interval > 0 && interval <= 60) { _checkInterval = interval * 60000; } if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password)) { LoginForm loginForm = new LoginForm(this); loginForm.Show(); return; } _loggedIn = true; _gmailClient = new GmailClient(username, password); Setup(); RefreshAndRestartTimer(); }
private void loginButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(usernameBox.Text) || String.IsNullOrEmpty(passwordBox.Text)) { ErrorBox("Please enter your username and password"); return; } mainPanel.Enabled = false; GmailClient gmailClient = new GmailClient(usernameBox.Text, passwordBox.Text); if (gmailClient.CheckEmail() != CheckEmailResult.Success) { mainPanel.Enabled = true; ErrorBox("Could not login\r\n\r\n" + gmailClient.LastError.Message); return; } byte[] pass = System.Security.Cryptography.ProtectedData.Protect(UTF8Encoding.UTF8.GetBytes(passwordBox.Text), null, System.Security.Cryptography.DataProtectionScope.CurrentUser); RegistryKey registry = Registry.CurrentUser.CreateSubKey(@"Software\KwertyGmailNotifier"); using (registry) { registry.SetValue("username", usernameBox.Text); registry.SetValue("password", pass); } _mainForm._gmailClient = gmailClient; _mainForm.Setup(); _mainForm._timer.Start(); _closed = true; Close(); }
private void Logout() { _processMsgClosed = true; _processMsg.Close(); lock (_timerLock) { _timerOn = false; _timer.Elapsed -= TimerElapsed; _timer.Stop(); _timer.Close(); } _gmailClient = null; _loggedIn = false; DestroySettingsForm(); RemoveJumpList(); RemoveThumbAndButtons(); UpdateIcon(); }