예제 #1
0
        public static string Validar_Login(Login_DTO obj)
        {
            try
            {
                string     sql = "select * from TB_LOGIN where usuario = @usuario AND senha = @senha";
                SqlCommand cm  = new SqlCommand(sql, Conexao_DAL.Login());

                cm.Parameters.AddWithValue("@usuario", obj.Usuario);
                cm.Parameters.AddWithValue("@senha", obj.Senha);
                SqlDataReader dados = cm.ExecuteReader(); //serve para executar
                while (dados.Read())                      //executa o loop para encontrar os dados
                {
                    if (dados.HasRows)                    //Se ele encontrar ele executa esse código, se achar ele coloca em um vetor
                    {
                        return("sucesso");
                    }
                }
                return("usuário ou senha inválidos!!");
            }

            catch (Exception xy)
            {
                return(xy.Message);
            }
        }
예제 #2
0
 private void btn_entrar_Click(object sender, EventArgs e)
 {
     try{
         Login_DTO obj = new Login_DTO();
         obj.Usuario = txt_usuario.Text;
         obj.Senha   = txt_senha.Text;
         string retorno;
         retorno = Login_BLL.ValidarLogin(obj);
         if (retorno == "sucesso")
         {
             this.Hide();
             Home tela = new Home();
             tela.ShowDialog();
             this.Close();
         }
         else
         {
             MessageBox.Show(retorno, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #3
0
        public static string ValidarLogin(Login_DTO obj)
        {
            try
            {
                string     script = "SELECT * FROM TB_LOGIN WHERE USUARIO = @USUARIO AND SENHA = @SENHA";
                SqlCommand cm     = new SqlCommand(script, Conexao.Conectar());
                cm.Parameters.AddWithValue("@USUARIO", obj.Usuario);
                cm.Parameters.AddWithValue("@SENHA", obj.Senha);

                SqlDataReader dados = cm.ExecuteReader();

                while (dados.Read())
                {
                    if (dados.HasRows)
                    {
                        return("sucesso");
                    }
                }
                return("USUÁRIO OU SENHA INVÁLIDOS!");
            }
            catch
            {
                throw new Exception("PROBLEMAS NA CONEXÃO");
            }
        }
예제 #4
0
        //Kiểm tra check User đăng nhập thành công hay không
        public ResultMessage_DTO CheckUserLogin(Login_DTO Login_DTO)
        {
            ResultMessage_DTO result = new ResultMessage_DTO();

            try
            {
                SqlCommand cmd = new SqlCommand("usp_USER_CheckUser", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@psUsername", Login_DTO.UserName);
                cmd.Parameters.AddWithValue("@psPassword", Login_DTO.PassWord);
                cmd.Parameters.AddWithValue("@pResultCode", result.ResultCode);
                cmd.Parameters.AddWithValue("@pResultMessage", result.ResultMessage);
                cmd.Parameters["@pResultCode"].Direction    = ParameterDirection.Output;
                cmd.Parameters["@pResultMessage"].Direction = ParameterDirection.Output;
                cmd.Parameters["@pResultMessage"].Size      = 50;
                con.Open();
                cmd.ExecuteNonQuery();
                result.ResultCode    = (int)cmd.Parameters["@pResultCode"].Value;
                result.ResultMessage = cmd.Parameters["@pResultMessage"].Value.ToString();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                result.ResultCode    = -1;
                result.ResultMessage = ex.Message;
            }
            finally
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
            }
            return(result);
        }
예제 #5
0
파일: ADM_Login.cs 프로젝트: lipe1997/DS
 private void btnLogar_Click(object sender, EventArgs e)
 {
     try
     {
         Login_DTO obj = new Login_DTO();
         obj.user  = txtUser.Text;
         obj.senha = txtPassword.Text;
         string msg = Login_BLL.Login(obj);
         if (msg == "tanana")
         {
             MessageBox.Show("Login successfully", "MSG", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             this.Hide();
             ADM_Home ah = new ADM_Home();
             ah.ShowDialog();
             this.Close();
         }
         else
         {
             MessageBox.Show("Invalid user or password", "MSG", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Errrrrooooo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #6
0
        public bool CheckLogin(Login_DTO lg)
        {
            try
            {
                con.Open();

                string SQL = string.Format("Select COUNT(TaiKhoan) FROM DangNhap WHERE TaiKhoan = N'" + lg.TaiKhoan +
                                           "' AND MatKhau = N'" + lg.MatKhau + "';");

                SqlCommand cmd = new SqlCommand(SQL, con);
                if ((int)cmd.ExecuteScalar() > 0)
                {
                    return(true);
                }
            }

            catch (Exception e)
            { }

            finally
            {
                con.Close();
            }

            return(false);
        }
예제 #7
0
        private void btn_dangnhap_Click(object sender, EventArgs e)
        {
            us  = txt_tendn.Text.Trim();
            pas = txt_matkhau.Text.Trim();

            if (us == string.Empty)
            {
                MessageBox.Show("Insert Username");
            }
            else if (pas == string.Empty)
            {
                MessageBox.Show("Insert PassWord");
            }
            else
            {
                if (Login_DAO.Instance.Login(us, pas))
                {
                    Login_DTO accout = Login_DAO.Instance.getaccout(us, pas);

                    frmQL frmql = new frmQL(accout.TypeUse);
                    frmql.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("Connect fail !!!");
                }
            }
        }
예제 #8
0
        public static string ValidarLogin(Login_DTO obj)
        {
            try
            {
                string     script = "SELECT * FROM TB_LOGIN WHERE USUARIO = @usuario AND SENHA = @senha"; //STRING RECEBENDO O RESULTADO DA CONSULTA NO BANCO DE DADOS;
                SqlCommand cm     = new SqlCommand(script, Conexao.Login());                              //RODA O SCRIPT EM UMA DETERMINADA SESSÃO;
                cm.Parameters.AddWithValue("@usuario", obj.Usuario);                                      //Passa como parametro para o Obj.Usuario o valor da busca no select @usuario;
                cm.Parameters.AddWithValue("@senha", obj.Senha);                                          //Passa como parametro para o Obj.Senha o valor da busca no select @senha;

                SqlDataReader dados = cm.ExecuteReader();
                while (dados.Read())   //Roda o script até achar algo;
                {
                    if (dados.HasRows) //Se achar alguma linha com a busca no banco de dados com usuario e senha correto sucesso
                    {
                        return("sucesso");
                    }
                }
                return("Usuário ou Senha inválida!"); //Se não achar nenhuma linha retorna erro;
            }
            catch                                     //(Exception ex)
            {
                throw new Exception("Problema na conexão!");
                //return (ex.Message);
            }
        }
        public async Task <IActionResult> Login([FromBody] Login_DTO loginDTO)
        {
            //LoginViewModel met (Required) UserName en Password aanbrengen.
            var returnMessage = "";

            if (!ModelState.IsValid)
            {
                return(BadRequest("Onvolledige gegevens."));
            }
            try
            {
                //geen persistence, geen lockout -> via false, false
                var result = await signInMgr.PasswordSignInAsync(loginDTO.UserName, loginDTO.Password, false, false);

                if (result.Succeeded)
                {
                    return(Ok("Welkom " + loginDTO.UserName));
                }
                throw new Exception("User of paswoord niet gevonden.");
                //zo algemeen mogelijk response. Vertelt niet dat het pwd niet juist is.
            }
            catch (Exception exc)
            {
                returnMessage = $"Foutief of ongeldig request: {exc.Message}";
                ModelState.AddModelError("", returnMessage);
            }
            return(BadRequest(returnMessage));
            //zo weinig mogelijk (hacker) info
        }
예제 #10
0
        public static bool ValidarLogin(Login_DTO obj)
        {
            try
            {
                string     script = "SELECT nome, usuario, senha FROM Administrador WHERE usuario = @Usuario AND senha = @Senha";
                SqlCommand cmd    = new SqlCommand(script, Conexao_DAL.Conexao());
                cmd.Parameters.AddWithValue("@Usuario", obj.Usuario);
                cmd.Parameters.AddWithValue("@Senha", obj.Senha);
                SqlDataReader dados = cmd.ExecuteReader();

                while (dados.Read())
                {
                    if (dados.HasRows)
                    {
                        obj.Nome = dados["nome"].ToString();
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                if (Conexao_DAL.Conexao().State != ConnectionState.Closed)
                {
                    Conexao_DAL.Conexao().Close();
                }
            }
        }
예제 #11
0
        public static bool CheckPermission(Login_DTO Login_DTO)
        {
            try
            {
                SqlConnection con   = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
                string        Query = "usp_USER_GetUserListPermision @UserName";
                con.Open();
                SqlCommand cmd = new SqlCommand(Query, con);

                SqlParameter UserName = new SqlParameter("@UserName", SqlDbType.VarChar);
                UserName.Value = Login_DTO.UserName;
                cmd.Parameters.Add(UserName);

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Login_DTO.Quyen = dt.Rows[i]["Quyen"].ToString();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #12
0
        private void BTNThemNV_Click(object sender, EventArgs e)
        {
            int    IDPQ = ctnv_BUS.GetIDPQ(txtChucVuNV.Text);
            string NGVL = DateTime.Now.ToString("yyyy/MM/dd");

            NhanVien_DTO kh_DTO = new NhanVien_DTO(IDPQ, txtTenNV.Text, txtSDTNV.Text, txtDCNV.Text, NGVL);

            if (nv_BUS.Insert(kh_DTO))
            {
                if (IDPQ <= 2)
                {
                    int       manv   = nv_BUS.getMANV(kh_DTO.HOTEN);
                    Login_DTO lg_DTO = new Login_DTO(kh_DTO.HOTEN, "1", manv);
                    if (lg_BUS.Insert(lg_DTO))
                    {
                        MessageBox.Show("Thêm thành công!");
                        LoadNV();
                        LoadTaiKhoan();
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại!");
                    }
                }
                else
                {
                    MessageBox.Show("Thêm thành công!");
                    LoadNV();
                }
            }
            else
            {
                MessageBox.Show("Thêm thất bại!");
            }
        }
예제 #13
0
        public static string ValidarLogin(Login_DTO obj)
        {
            try
            {
                string       script = "SELECT * FROM tb_login WHERE login = @login AND senha = @senha";
                MySqlCommand cm     = new MySqlCommand(script, Conexao.Conectar());
                cm.Parameters.AddWithValue("@login", obj.Usuario);
                cm.Parameters.AddWithValue("@senha", obj.Senha);

                MySqlDataReader dados = cm.ExecuteReader();

                while (dados.Read())
                {
                    if (dados.HasRows)
                    {
                        return("sucesso");
                    }
                }
                return("Usuário ou senha inválidos!");
            }
            catch
            {
                throw new Exception("Problemas na conexão!");
            }
        }
예제 #14
0
        private void btnIniciar_Click(object sender, EventArgs e)
        {
            Login_DTO obj = new Login_DTO();
            bool      login;

            try
            {
                obj.Usuario = textBox1.Text;
                obj.Senha   = textBox2.Text;
                login       = Login_BLL.ValidarLogin(obj);
                if (login == true)
                {
                    this.Hide();
                    Home inicio = new Home();
                    inicio.ShowDialog();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Usuário ou Senha Inválidos", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #15
0
        public static string login(Login_DTO obj)
        {
            try
            {
                string     sql = "SELECT * FROM tb_login where usuario = @usuario and senha = @senha";
                SqlCommand cmd = new SqlCommand(sql, Conexao.Login());
                cmd.Parameters.AddWithValue("@usuario", obj.user);
                cmd.Parameters.AddWithValue("@senha", obj.senha);
                SqlDataReader ler = cmd.ExecuteReader();
                string        msg = "lalala";

                while (ler.Read())
                {
                    if (ler.HasRows)
                    {
                        msg = "tanana";
                        return(msg);
                    }
                }
                return(msg);
            }
            catch
            {
                throw new Exception("Houve um erro ao conectar com o banco");
            }
            finally
            {
                if (Conexao.Login().State != ConnectionState.Closed)
                {
                    Conexao.Login().Close();
                }
            }
        }
예제 #16
0
        private void btnEntrar_Click(object sender, EventArgs e)
        {
            try
            {
                Login_DTO obj = new Login_DTO();
                obj.Usuario = txtUsuario.Text;
                obj.Senha   = txtSenha.Text;
                string retorno;
                retorno = Login_BLL.ValidarLogin(obj);
                if (retorno == "sucesso")
                {
                    this.Hide();
                    Home Tela = new Home();
                    Tela.ShowDialog();
                    this.Close();
                }
                else
                {
                    MessageBox.Show(retorno, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            /*catch (Exception ex)//MOSTRA A EXCEÇÃO NO BANCO, PORÉM COM SOFTWARE PRONTO NÃO É BOM MOSTRAR PARA O USUÁRIO!!
             * {
             *
             *  MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
             * }*/
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #17
0
        private void txtEntrar_Click(object sender, EventArgs e)
        {
            try
            {
                Login_DTO obj = new Login_DTO();       //Cria o objeto para receber os valores das caixas de Texto.
                obj.Usuario = txtUser.Text;            //Objeto recebendo o valor na propriedade Text.
                obj.Senha   = txtSenha.Text;           //Objeto recebendo o valor na propriedade Text.
                string retorno;                        //Criando a variavel.
                retorno = Login_BLL.ValidarLogin(obj); //Variavel recebendo o objeto da Classe Bll validada.
                if (retorno == "sucesso")
                {
                    this.Hide();
                    Home tela = new Home();
                    tela.ShowDialog();
                    this.Close();
                }
                else
                {
                    MessageBox.Show(retorno, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //Identar código automáticamente = CTRL + K + D.
        }
예제 #18
0
파일: Login.cs 프로젝트: Pelaes/Projetos_DS
 private void btnLogar_Click(object sender, EventArgs e)
 {
     try
     {
         Login_DTO login = new Login_DTO();
         login.Login     = txtUsuario.Text;
         login.Senha     = txtSenha.Text;
         login.ConfSenha = txtConSenha.Text;
         login           = Login_BLL.ValidarLogin(login);
         if (!(login.ID.Equals("")))
         {
             this.Hide();
             Home tela = new Home(login);
             tela.ShowDialog();
             this.Close();
         }
         else
         {
             MessageBox.Show("Usuário e/ou senha inválidos", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        public ActionResult Login(Login_Model MyModel)
        {
            Login_DTO MyLogin_DTO = MyRepository.AuthenticationUser(MyModel);

            if (MyLogin_DTO != null && MyLogin_DTO.Result.StartsWith("success"))
            {
                MyLogin_DTO.Result     = MyLogin_DTO.Result.Replace("success:", "");
                SessionComponent.UID   = MyLogin_DTO.ID;
                SessionComponent.UName = MyLogin_DTO.vName;

                SessionComponent.SessionID = Session.SessionID;

                return(RedirectToAction("Index", "Travel"));
            }
            else if (MyLogin_DTO != null && MyLogin_DTO.Result.StartsWith("fail"))
            {
                MyLogin_DTO.Result       = MyLogin_DTO.Result.Replace("fail:", "");
                TempData["msg"]          = MyLogin_DTO.Result;
                TempData["Notification"] = Notification_Component.SetNotification((int)Notification_Component.Result.Info, MyLogin_DTO.Result);

                return(RedirectToAction("Login"));
            }
            else
            {
                TempData["msg"]          = "Invalid credentials,Please try again!";
                TempData["Notification"] = Notification_Component.SetNotification((int)Notification_Component.Result.Info, "Invalid credentials,Please try again!");

                return(RedirectToAction("Login"));

                // TempData["Notification"] = Notification_Component.SetNotification((int)Notification_Component.Result.Info, "Invalid credentials,Please try again!");
            }
        }
예제 #20
0
        public Login_DTO getaccout(string us, string pas)
        {
            string    query = "SELECT * FROM dbo.UserLog WHERE UserName=N'" + us + " ' AND Pass=N'" + pas + " '";
            Login_DTO acc;
            DataTable tb = DBConect_DAO.Instrance.ExecuteQuery(query);

            acc = new Login_DTO(tb.Rows[0]);
            return(acc);
        }
예제 #21
0
 public ResultMessage_DTO CheckUserLoginBL(Login_DTO Login_DTO)
 {
     try
     {
         Login_DAO DangNhap = new Login_DAO();       // Creating object of Dataccess
         return(DangNhap.CheckUserLogin(Login_DTO)); // calling Method of DataAccess
     }
     catch
     {
         throw;
     }
 }
예제 #22
0
 public ResultMessage_DTO SaveUserregisrationBL(Login_DTO Login_DTO) // passing Bussiness object Here
 {
     try
     {
         Login_DAO DangNhap = new Login_DAO();       // Creating object of Dataccess
         return(DangNhap.AddUserDetails(Login_DTO)); // calling Method of DataAccess
     }
     catch
     {
         throw;
     }
 }
예제 #23
0
 public static string ValidarLogin(Login_DTO obj)
 {
     if (string.IsNullOrWhiteSpace(obj.Usuario))
     {
         return("CAMPO USUÁRIO VAZIO!");
     }
     if (string.IsNullOrWhiteSpace(obj.Senha))
     {
         return("CAMPO SENHA VAZIO!");
     }
     return(Login_DAL.ValidarLogin(obj));
 }
예제 #24
0
        public static string ValidarLogin(Login_DTO obj)
        {
            if (string.IsNullOrWhiteSpace(obj.Usuario))
            {
                return("Campo usuário vazio!");
            }
            if (string.IsNullOrWhiteSpace(obj.Senha))
            {
                return("Campo senha vazio!");
            }

            return(Login_DAL.ValidarLogin(obj));
        }
예제 #25
0
        public static string Login(Login_DTO obj)
        {
            if (string.IsNullOrWhiteSpace(obj.user))
            {
                throw new Exception("User Empty");
            }
            if (string.IsNullOrWhiteSpace(obj.senha))
            {
                throw new Exception("Password Empty");
            }
            string msg = Login_DAL.login(obj);

            return(msg);
        }
예제 #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            ResultMessage_DTO result;
            Login_DTO         Login_DTO = new Login_DTO();
            Login_BUS         Login_BUS = new Login_BUS();

            Login_DTO.UserName = tbUsername.Text;
            Login_DTO.PassWord = tbPassword.Text;
            result             = Login_BUS.SaveUserregisrationBL(Login_DTO);
            if (result.ResultCode > 0)
            {
                frmView fView = new frmView();
                UserID       = result.ResultCode;
                fView.UserID = UserID;
                MessageBox.Show(result.ResultMessage, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (Login_BUS.CheckPermission(Login_DTO) == true)
                {
                    if (Login_DTO.Quyen == "nhanvien")
                    {
                        fView.doanhThuToolStripMenuItem.Enabled = false;
                        fView.quảnLíToolStripMenuItem.Enabled   = false;
                    }
                    else
                    {
                        fView.NhanVienToolStripMenuItem.Enabled    = true;
                        fView.nhàCungCấpToolStripMenuItem1.Enabled = true;
                        fView.doanhThuToolStripMenuItem.Enabled    = true;
                    }
                }
                fView.ShowDialog();
            }
            else
            {
                MessageBox.Show(result.ResultMessage, "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbUsername.Text = "";
                tbPassword.Text = "";
                if (iLoginFailed < cNumberLoginFailed)
                {
                    iLoginFailed     += 1;
                    this.DialogResult = DialogResult.None;
                }
                else
                {
                    this.DialogResult = DialogResult.Cancel;
                }
            }
        }
예제 #27
0
 private void LoginEnviar_Click(object sender, EventArgs e)
 {
     try
     {
         Login_DTO obj = new Login_DTO();
         obj.Usuario = textBoxUsuario.Text;
         obj.Senha   = textBoxSenha.Text;
         Login_BLL.ValidarLogin(obj);
         Form1 telaInicial = new Form1();
         telaInicial.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #28
0
        public static string ValidarLogin(Login_DTO obj)
        {
            if (string.IsNullOrWhiteSpace(obj.Usuario))
            {
                return("Campo usuário Vazio");
            }
            if (string.IsNullOrWhiteSpace(obj.Senha))
            {
                return("Campo senha Vazio");
            }
            return(Login_DAL.Validar_Login(obj));
            //return "Sucesso!!";

            /*if (obj.Senha != confsenha)
             * {
             *  throw new Exception("Senhas Diferentes!!");
             * }*/
        }
예제 #29
0
        public async Task <IActionResult> Token([FromBody] Login_DTO
                                                identityDTO)
        {
            try
            {
                var jwtsvc = new JWTServices <Person>(configuration,
                                                      logger, userManager, hasher);
                var token = await jwtsvc.GenerateJwtToken(identityDTO);

                return(Ok(token));
            }
            catch (Exception exc)
            {
                logger.LogError($"Exception thrown when creating JWT: {exc}");
            }
            //Bij niet succesvolle authenticatie wordt een Badrequest (=zo weinig mogelijke info) teruggeven.
            return(BadRequest("Failed to generate JWT token"));
        }
예제 #30
0
 public static bool ValidarLogin(Login_DTO obj)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(obj.Usuario))
         {
             throw new Exception("Campo Usuário é obrigatório.");
         }
         if (string.IsNullOrWhiteSpace(obj.Senha))
         {
             throw new Exception("Campo Senha é obrigatório.");
         }
         return(Login_DAL.ValidarLogin(obj));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }