private async Task LoginProcess() { // ID, Password 빈칸일경우 재입력 요청 if (string.IsNullOrEmpty(TxtUserId.Text) || string.IsNullOrEmpty(TxtUserPwd.Text)) { MetroMessageBox.Show(this, "ID, Password를 입력해주세요.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information); TxtUserId.Focus(); return; } // DB에 연결하여 로그인정보 확인 try { using (MySqlConnection connection = new MySqlConnection(Commons.CONNSTR)) { await connection.OpenAsync(); //MetroMessageBox.Show(this, "DB Connection OK."); MySqlCommand command = new MySqlCommand() { Connection = connection }; command.CommandText = @"SELECT userID FROM usertbl WHERE userID = @userID AND password = @password"; MySqlParameter userId = new MySqlParameter("@userID", MySqlDbType.VarChar, TxtUserId.Text.Length); userId.Value = TxtUserId.Text.Trim(); command.Parameters.Add(userId); MySqlParameter userPwd = new MySqlParameter("@password", MySqlDbType.VarChar, TxtUserPwd.Text.Length); userPwd.Value = TxtUserPwd.Text.Trim(); command.Parameters.Add(userPwd); MySqlDataReader reader = await Task.Run(() => command.ExecuteReader()); await reader.ReadAsync(); string resultId = reader["userID"]?.ToString(); if (reader.HasRows == false || string.IsNullOrEmpty(resultId)) { MetroMessageBox.Show(this, "ID / Password check again", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); TxtUserId.Clear(); TxtUserPwd.Clear(); TxtUserId.Focus(); return; } else { MetroMessageBox.Show(this, $"{resultId} Login"); this.Owner.Focus(); this.Close(); } } } catch (Exception ex) { MetroMessageBox.Show(this, $"DB Connection Error: {ex.Message}", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
private void submitButton_Click(object sender, EventArgs e) { string CurrentPWD, UserName; string UserID = TxtUserId.Text; if ((UserID == string.Empty) || (UserID == " ")) { MessageBox.Show("You must enter a valid User ID to continue", "Application Security"); TxtUserId.Clear(); TxtUserId.Select(); return; } bool ReturnValue = PawnLDAPAccessor.Instance.GetUserPassword(UserID, out CurrentPWD, out UserName); if (ReturnValue == false) { MessageBox.Show(UserID + " is not a valid User ID", "Application Security"); TxtUserId.Clear(); TxtUserId.Select(); return; } if (UserName == string.Empty) { MessageBox.Show(UserID + "You must enter a valid User ID to continue", "Application Security"); TxtUserId.Clear(); TxtUserId.Select(); return; } TextInfo info = CultureInfo.CurrentCulture.TextInfo; UserName = info.ToTitleCase(UserName.ToLower()); DialogResult reply = MessageBox.Show(string.Format("Are you sure you want to reset the password for {0}?", UserName), "Application Security", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (reply == DialogResult.Yes) { string UserDN = string.Format("uid={0},ou=People,dc=cashamerica", UserID); ReturnValue = PawnLDAPAccessor.Instance.ChangePassword(UserDN, "xyz12345"); if (ReturnValue) { MessageBox.Show(string.Format("Password successfully changed for {0} to 'xyz12345'.", UserName), "Application Security"); CashlinxPawnSupportSession.Instance.LoggedInUserSecurityProfile.UserCurrentPassword = "******"; this.Close(); } else { MessageBox.Show(string.Format("{0}Error Changing Password", UserID), "System Error"); return; } } else { return; } }