public LoginForm() { TriesLeft = 3; AuthenticationState = AuthenticationStates.None; InitializeComponent(); }
internal void SetAuthState(AuthenticationStates state) { authState = state; }
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"); }
private void buttonCancel_Click(object sender, EventArgs e) { AuthenticationState = AuthenticationStates.None; this.Close(); }