public static bool login(user ExisitingUser, MetroForm ui) { try { row = UserDataTable.FindByusername(ExisitingUser.username); if (row == null) { MSG.ERROR(ui, "User Doesn't Exists in the System"); return(false); } if ((row.username.ToString() == ExisitingUser.username) && (row.password.ToString() == ExisitingUser.password)) { MSG.SUCCESS(ui, "Login Success.!"); ui.Hide(); frm_dashboard n = new frm_dashboard(); n.ShowDialog(); ui.Close(); return(true); } else { MSG.ERROR(ui, "Username and Password Doesn't Match!"); return(false); } } catch (MySql.Data.MySqlClient.MySqlException ex) { MSG.ERROR(ui, "Login Error.!, " + ex.Message); return(false); } }
private void btn_Login_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(tb_username.Text) == true) { tb_username.Focus(); errorProvider_user.SetError(tb_username, "please fill the field"); } else if (string.IsNullOrWhiteSpace(tb_Password.Text) == true) { tb_Password.Focus(); errorProvider_pass.SetError(tb_Password, "please fill the field"); } else { try { string UserName = tb_username.Text; string Password = tb_Password.Text; Login login = new Login(); login.User_Name = UserName; login.Pass_word = Password; bool check = login.checkUser(); if (check) { Common.adminId = login.getId(); this.Hide(); frm_dashboard obj = new frm_dashboard(); obj.ShowDialog(); } else { MessageBox.Show("Sorry You Are Not Allowed"); } resetData(); MessageBox.Show("Done and Thank You"); } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); } } }