private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e) { CheckPasswordForm checkPasswordForm = new CheckPasswordForm() { Password = this.CurrentUser.Password }; checkPasswordForm.ShowDialog(); if (checkPasswordForm.DialogResult == System.Windows.Forms.DialogResult.OK) { ChangePasswordForm cpf = new ChangePasswordForm(); if (AuthenticationState == AuthenticationStates.User) { cpf.UserInfo = CurrentUser as UserInfo; } else { cpf.UserInfo = null; } cpf.ShowDialog(); if (cpf.DialogResult != System.Windows.Forms.DialogResult.OK) { return; } CurrentUser.Password = cpf.Password; StoredData data; StoredData.LoadUserList(StoredData.FileName, out data); if (this.AuthenticationState == AuthenticationStates.User) { data.Users.First(u => u.Name.Equals(CurrentUser.Name)). Password = CurrentUser.Password; } else { data.Admin.Password = CurrentUser.Password; } data.SaveToFile(StoredData.FileName); } }
private void buttonOk_Click(object sender, EventArgs e) { string userName = textBoxUser.Text; string password = textBoxPassword.Text; if (StoredData.Admin.Name.Equals(userName)) { if (StoredData.Admin.Password == null) { ChangePasswordForm cpf = new ChangePasswordForm(); cpf.ShowDialog(); if (cpf.DialogResult != System.Windows.Forms.DialogResult.OK) { return; } StoredData.Admin.Password = cpf.Password; StoredData.SaveToFile(StoredData.FileName); // start as admin CurrentUser = StoredData.Admin; AuthenticationState = AuthenticationStates.Admin; this.Close(); } if (StoredData.Admin.Password.Equals(password)) { // start as admin CurrentUser = StoredData.Admin; AuthenticationState = AuthenticationStates.Admin; this.Close(); } else { TreatIncorrectPassword(); } return; } if (StoredData.Users.Any(u => u.Name.Equals(userName))) { UserInfo user = StoredData.Users.First(u => u.Name.Equals(userName)); if (user.Password == null) { if (user.Blocked) { MessageBox.Show("the user name is blocked."); return; } ChangePasswordForm cpf = new ChangePasswordForm(); cpf.UserInfo = user as UserInfo; cpf.ShowDialog(); if (cpf.DialogResult != System.Windows.Forms.DialogResult.OK) { return; } user.Password = cpf.Password; StoredData.SaveToFile(StoredData.FileName); // start as the selected user CurrentUser = user; AuthenticationState = AuthenticationStates.User; this.Close(); } if (user.Password.Equals(password)) { if (user.Blocked) { MessageBox.Show("the user name is blocked."); return; } // start as the selected user CurrentUser = user; AuthenticationState = AuthenticationStates.User; this.Close(); } else { TreatIncorrectPassword(); } return; } MessageBox.Show("Username doesn't exist. Please try again"); }