diff --git a/Authorization.cs b/Authorization.cs index 66eddc8..25b3ded 100644 --- a/Authorization.cs +++ b/Authorization.cs @@ -91,13 +91,28 @@ namespace AwesomeEmailExtractor { SqliteCommand command = new SqliteCommand(); command.Connection = Globals.db; - command.CommandText = "DELETE FROM users WHERE id = @id"; + command.CommandText = "DELETE FROM users WHERE id = @id;"; - SqliteParameter loginParam = new SqliteParameter("@id", ID); - command.Parameters.Add(loginParam); + SqliteParameter idParam = new SqliteParameter("@id", ID); + command.Parameters.Add(idParam); command.ExecuteNonQuery(); } + + public void ChangePassword(string password) + { + SqliteCommand command = new SqliteCommand(); + command.Connection = Globals.db; + command.CommandText = "UPDATE users SET password = @password WHERE id = @id;"; + + SqliteParameter idParam = new SqliteParameter("@id", ID); + command.Parameters.Add(idParam); + + SqliteParameter passwordParam = new SqliteParameter("@password", Authorization.EncryptPassword(password)); + command.Parameters.Add(passwordParam); + + command.ExecuteNonQuery(); + } } public class AdminUtils diff --git a/SettingsForm.Designer.cs b/SettingsForm.Designer.cs index c139b18..e4c61bf 100644 --- a/SettingsForm.Designer.cs +++ b/SettingsForm.Designer.cs @@ -44,6 +44,7 @@ this.changePasswordButton.TabIndex = 0; this.changePasswordButton.Text = "Изменить пароль"; this.changePasswordButton.UseVisualStyleBackColor = true; + this.changePasswordButton.Click += new System.EventHandler(this.changePasswordButton_Click); // // entryNewPassword // diff --git a/SettingsForm.cs b/SettingsForm.cs index 5d516e9..9d3aaac 100644 --- a/SettingsForm.cs +++ b/SettingsForm.cs @@ -24,7 +24,7 @@ namespace AwesomeEmailExtractor if (result == DialogResult.Yes) { Globals.currentUser.Delete(); - MessageBox.Show("Аккаунт удален"); + MessageBox.Show("Аккаунт удален!"); this.Close(); @@ -32,5 +32,17 @@ namespace AwesomeEmailExtractor FormManager.Current.Navigate(this.Owner, authorization); } } + + private void changePasswordButton_Click(object sender, EventArgs e) + { + if (!string.Equals(entryNewPassword.Text, entryRePassword.Text)) + { + MessageBox.Show("Пароли не совпадают!"); + return; + } + + Globals.currentUser.ChangePassword(entryNewPassword.Text); + MessageBox.Show("Пароль изменен!"); + } } }