public bool loginCheck(loginBLL l) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstring); try { string sql = "SELECT * FROM tbl_users WHERE username=@username AND password=@password AND user_type=@user_type"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); cmd.Parameters.AddWithValue("@user_type", l.user_type); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public int loginCheck(loginBLL login) { //Create a boolean variable and set its value to false and return it int isSuccess = 0; SqlConnection connection = new SqlConnection(myconnectionstring); try { //SQL Query to check login string sql = "SELECT user_type FROM tbl_users Where username=@username AND password=@password"; //Creating SQL command to pass vale SqlCommand cmd = new SqlCommand(sql, connection); cmd.Parameters.AddWithValue("@username", login.username); cmd.Parameters.AddWithValue("@password", login.password); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); string user_type = dataTable.Rows[0].Field <string>(0); //Checking the roews in datatable if (dataTable.Rows.Count > 0) { if (user_type.ToLower() == "admin") { isSuccess = 1; } if (user_type.ToLower() == "staff") { isSuccess = 2; } } else { // Login failed isSuccess = 0; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } return(isSuccess); }
public bool loginCheck(loginBLL l) { //create a boolean variable and set its default value to false bool isSuccess = false; //connecting db SqlConnection conn = new SqlConnection(); try { //sql query to check login based on username and password string sql = "SELECT * FROM table_users WHERE username = @username AND password = @password"; //create sql command to pass the value to sql query SqlCommand cmd = new SqlCommand(sql, conn); //pass the value to sql query using parameters cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); //sql data adapter to get the data from db SqlDataAdapter adapter = new SqlDataAdapter(cmd); //data table to hold the data from db temporarily DataTable dt = new DataTable(); //fill the data from adapter to dt adapter.Fill(dt); //check if user exists if (dt.Rows.Count > 0) { //user exists and login successfull isSuccess = true; } else { //login failed isSuccess = false; } } catch (Exception e) { //display error if there are any exception errors MessageBox.Show(e.Message); } finally { //close db connection conn.Close(); } return(isSuccess); }
public bool loginCheck(loginBLL l) { //Create a Boolean Variable and SEt its default value to false bool isSuccess = false; //Connecting DAtabase SqlConnection conn = new SqlConnection(myconnstrng); try { //SQL Query to Check Login BAsed on Usename and Password string sql = "SELECT * FROM tbl_users WHERE username=@username AND password=@password"; //Create SQL Command to Pass the value to SQL Query SqlCommand cmd = new SqlCommand(sql, conn); //Pass the value to SQL Query Using Parameters cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); //SQl Data Adapeter to Get the Data from Database SqlDataAdapter adapter = new SqlDataAdapter(cmd); //DataTable to Hold the data from database temporarily DataTable dt = new DataTable(); //Filld the data from adapter to dt adapter.Fill(dt); //Chekc whether user exists or not if (dt.Rows.Count > 0) { //User Exists and Login Successful isSuccess = true; } else { //Login Failed isSuccess = false; } } catch (Exception ex) { //Display Error Message if there's any Exception Errors MessageBox.Show(ex.Message); } finally { //Close Database Connection conn.Close(); } return(isSuccess); }
private void btnEntrarLogin_Click(object sender, EventArgs e) { loginBLL l = new loginBLL(); loginDados d = new loginDados(); l.usuario = txtUsuarioLogin.Text.Trim(); l.senha = txtSenhaLogin.Text.Trim(); l.tipo_usuario = cmbTipoUsuarioLogin.Text; bool logado = d.loginCheck(l); if (logado) { MessageBox.Show("Logado com sucesso!"); switch (l.tipo_usuario) { case "Administrador": { this.Close(); newThread = new Thread(novaJanelaAdmin); newThread.SetApartmentState(ApartmentState.STA); newThread.Start(); /**frmAdminDashboard admin = new frmAdminDashboard(); * admin.Show(); * this.Hide(); */ break; } case "Usuário": { this.Close(); newThread = new Thread(novaJanelaUser); newThread.SetApartmentState(ApartmentState.STA); newThread.Start(); break; } default: { MessageBox.Show("Inválido"); break; } } } else { MessageBox.Show("Usuário ou senha inválidos"); } }
public bool loginCheck(loginBLL l) { //creaate bool var and set its value to false and return it bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { //SQL query to check login string sql = "SELECT * FROM tbl_users WHERE username=@username AND password=@password AND user_type=@user_type"; //SQL command to pass value SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); cmd.Parameters.AddWithValue("@user_type", l.user_type); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { //MessageBox.Show("Login Succesfull"); isSuccess = true; } else { //MessageBox.Show("Login failed"); isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public bool loginCheck(loginBLL l) { //create a boolean variable and set its value to false and return it bool isSuccess = false; //connecting to database SqlConnection conn = new SqlConnection(myconnstrng); try { //Sql query to check login string sql = "SELECT* FROM tbl_users WHERE username=@username AND password=@password AND user_type=@user_type"; //creating sql command to pass value SqlCommand cmd = new SqlCommand(sql, conn); //using query to get the data cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); cmd.Parameters.AddWithValue("@user_type", l.user_type); //storing the data in adapter SqlDataAdapter adapter = new SqlDataAdapter(cmd); //filling the datatable DataTable dt = new DataTable(); adapter.Fill(dt); //checking the rows in dataTable if (dt.Rows.Count > 0) { //login successful isSuccess = true; } else { //login failed isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
private void loginHandler_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(this.txt_username.Text) || string.IsNullOrWhiteSpace(this.txt_password.Password.ToString())) { if (string.IsNullOrWhiteSpace(this.txt_username.Text)) { txt_username.Background = Brushes.Red; } if (string.IsNullOrWhiteSpace(this.txt_password.Password.ToString())) { txt_password.Background = Brushes.Red; } MessageBox.Show("Validate"); return; } loginBLL aBLL = new loginBLL(); loginBO lBO = new loginBO(); lBO.Username = this.txt_username.Text; lBO.Password = this.txt_password.Password.ToString(); int rv; rv = aBLL.login(lBO); if (rv == 1) { //MessageBox.Show("Loged in"); //this.Show(adminPanel.x); adminPanel a = new adminPanel(); this.Hide(); a.Show(); } else if (rv == 2) { //MessageBox.Show("User Panael"); global.user = this.txt_username.Text; userPanel u = new userPanel(); this.Hide(); u.Show(); } else if (rv == 3) { MessageBox.Show("User Do Not Exist"); } else if (rv == 4) { MessageBox.Show("Invalid Username/Password"); } }
public bool loginCheck(loginBLL l) { bool isSuccess = false; //Connecting to database SqlConnection conn = new SqlConnection(myconnstrng); try { //SQL Query to check login String sql = "SELECT * FROM tbl_users WHERE username=@username AND password=@password AND user_type=@user_type"; //Creating SQl Command to pass values SqlCommand cmd = new SqlCommand(sql, conn); //passing values using parameters cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); cmd.Parameters.AddWithValue("@user_type", l.userType); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); //check login successfull by counting rows if (dt.Rows.Count > 0) { //login Successfull isSuccess = true; } else { //Login Failed isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public bool loginCheck(loginBLL l) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myConnstring); try { string sql = "SELECT * FROM tbl_usuario WHERE username=@username AND password=@password AND user_type=@user_type"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); cmd.Parameters.AddWithValue("@user_type", l.user_type); //SqlDataAdapter - preencher o DataSet e atualizar o banco de dados do SQL Server. // SQL Data Adapter para reter os dados do banco de dados temporariamente SqlDataAdapter adapter = new SqlDataAdapter(cmd); //DataTable - Representa uma tabela de dados na memória. // Criando DataTable para manter o valor do dAtabase //Um DataTable é como um container que podemos usar para armazenar informações de //praticamente qualquer fonte de dados, sendo composto por uma coleção de linhas (rows) //e colunas (columns) DataTable dt = new DataTable(); //Um SqlCommand usado durante o Fill(DataSet) //para selecionar registros do banco de dados para posicionamento no DataSet. //FILL - Preenche um DataSet ou DataTable. adapter.Fill(dt); if (dt.Rows.Count > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
private void btnLogin_Click_1(object sender, EventArgs e) { try { Login login = new Login(); string userName = txtUser.Text; login.username = int.Parse(txtUser.Text); login.password = int.Parse(txtPass.Text); UserInfo.Id = int.Parse(userName); loginBLL logbll = new loginBLL(); bool kq = logbll.CheckLogin(login); if (kq == true) { MessageBox.Show(login.permission.ToString()); if (login.permission == "QLBH") { this.Hide(); frm_Main main = new frm_Main(login.fullname, login.namepermision); UserInfo.permission = login.permission; main.ShowDialog(); this.Close(); } else if (login.permission == "NVBH") { this.Hide(); frm_Main main = new frm_Main(login.fullname, login.namepermision); UserInfo.permission = login.permission; main.ShowDialog(); this.Close(); } else if (login.permission == "NVNEW") { MessageBox.Show("Bạn không có quyền đăng nhập vào hệ thống!"); } } } catch { MessageBox.Show("Username hoặc Password không đúng"); } }
public bool loginCheck(loginBLL l) { //create a boolean variable and set its value to false and return it bool isSuccess = false; // Method to connect to database SqlConnection conn = new SqlConnection(myconnstrng); try { //Query to check login of dtabase String sql = "SELECT * FROM dbo.users WHERE username=@username AND password=@password AND userType=@userType"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@username", l.userName); cmd.Parameters.AddWithValue("@password", l.password); cmd.Parameters.AddWithValue("@userType", l.userType); SqlDataAdapter adapter = new SqlDataAdapter(cmd); //This is used to hold data from the database DataTable dt = new DataTable(); adapter.Fill(dt); //Checking number of rows in datatable if (dt.Rows.Count > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { //Show error message for any messages that might occur MessageBox.Show(ex.Message); } finally { //Close Connection conn.Close(); } return(isSuccess); }
public void ProcessRequest(HttpContext context) { //string s = ""; context.Response.ContentType = "text/plain"; // context.Response.Write("Hello World");' string username = context.Request.Form["txtn"].ToString(); string userPwd = context.Request["txtp"].ToString(); loginBLL bll = new loginBLL(); if (userPwd == bll.getadminPwd(username)) { context.Response.Redirect("../default.aspx"); } else { context.Response.Redirect("../login.aspx"); } }
public bool loginCheck(loginBLL l) { //create a boolean variable and set it's value to false and return it bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstring); try { //sql query to check login string sql = "Select * from tbl_users WHERE username=@username AND password=@password AND user_type=@user_type"; //Creating sql command to pass the values SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); cmd.Parameters.AddWithValue("@user_type", l.user_type); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { // MessageBox.Show("Login is succesfull"); isSuccess = true; } else { //MessageBox.Show("login Failed ..!!! :/"); isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public bool loginCheck(loginBLL l) { bool isSuccess = false; SqlConnection conn = getConnection(); try { string sql = "SELECT * FROM tabela_user WHERE username = @username AND pass LIKE @pass AND user_type = @tipousuario"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@username", l.usuario); cmd.Parameters.AddWithValue("@pass", l.senha); cmd.Parameters.AddWithValue("@tipousuario", l.tipo_usuario); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); conn.Open(); if (dt.Rows.Count > 0) { isSuccess = true; } else { isSuccess = false; } //isSuccess = true; } catch (Exception err) { MessageBox.Show(err.Message); } finally { conn.Close(); } return(isSuccess); }
public bool loginProvjera(loginBLL l) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "SELECT * FROM tbl_korisnici WHERE korisnicko_ime=@korisnicko_ime AND lozinka=@lozinka"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@korisnicko_ime", l.korisnickoIme); cmd.Parameters.AddWithValue("@lozinka", l.lozinka); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
private void loginValid() { loginBLL l = new loginBLL(); DataTable dt; dt = l.login(txtUserName.Text, txtPassword.Text); //MessageBox.Show("" + dt.Rows.Count); if (dt.Rows.Count == 1) { string status = dt.Rows[0][4].ToString(); if (status.Equals("valid")) { string des = dt.Rows[0][3].ToString(); long id = Convert.ToInt64(dt.Rows[0][0].ToString()); string name = dt.Rows[0][5].ToString(); if (des.Equals("admin")) { this.Hide(); frmAdmin adm = new frmAdmin(id, name); adm.Show(); } else if (des.Equals("salesman")) { this.Hide(); frmSalesman adm = new frmSalesman(id, name); adm.Show(); } } else { lblLogin.Text = "you are invalid"; } } else { lblLogin.Text = "User name or Password not matched"; } }
static string myConnString = Program.CS;//ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString; public bool loginCheck(loginBLL l) { bool isSuccess = false; SqlCeConnection con = new SqlCeConnection(myConnString); try { string comm = "select * from tbl_users WHERE username=@username and password=@password and user_type=@user_type"; SqlCeCommand cmd = new SqlCeCommand(comm, con); cmd.Parameters.AddWithValue("@username", l.username); cmd.Parameters.AddWithValue("@password", l.password); cmd.Parameters.AddWithValue("@user_type", l.user_type); SqlCeDataAdapter adapter = new SqlCeDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); if (dt.Rows.Count > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { new Mymessage(ex.Message); } finally { con.Close(); } return(isSuccess); }
private int addLogin() { loginBLL log = new loginBLL(); return(log.logEmployee(nxtId, txtUserName.Text, txtPassword.Text)); }