Exemplo n.º 1
0
        private void btnEntrar_Click(object sender, EventArgs e)
        {
            string rol;
            string userStored;
            string passStored;
            string userInput = txbUser.Text;
            string passInput = txbPass.Text;
            string salt = ConfigurationManager.AppSettings["salt"];
            passInput= Hash.sha1(Hash.md5(passInput + salt));
            string sql = "SELECT * FROM Usuarios WHERE username ='******' AND password ='******'";

            if (Vacio.txb(this))
            {
                db.buscar(sql);
                if (db.ds.Tables[0].Rows.Count > 0)
                {
                    userStored = Convert.ToString(db.ds.Tables[0].Rows[0]["username"]);
                    passStored = Convert.ToString(db.ds.Tables[0].Rows[0]["password"]);
                    rol = Convert.ToString(db.ds.Tables[0].Rows[0]["rol"]);

                    if (userInput == userStored && passInput == passStored && rol == "Administrador")
                    {
                        this.Hide();
                        AdminMDI mdiA = new AdminMDI();
                        mdiA.Show();
                    }

                    if (userInput == userStored && passInput == passStored && rol == "Usuario")
                    {
                        this.Hide();
                        UserMDI mdiU = new UserMDI();
                        mdiU.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Datos incorrectos", "Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Limpiar.txb(this);
                    txbUser.Focus();
                }
            }
            else
            {
                MessageBox.Show("Debes de llenar ambos campos", "Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }      
        }
Exemplo n.º 2
0
        private void btnEntrar_Click(object sender, EventArgs e)
        {
            string userR;
            string passR;
            int    tipo;
            string user = txbUser.Text;
            string pass = txbPass.Text;
            string sql  = "SELECT * FROM Usuarios WHERE noUsu ='" + user + "' AND pwUsu ='" + pass + "'";

            if (Vacio.txb(this))
            {
                db.buscar(sql);
                if (db.dt.Rows.Count > 0)
                {
                    DataRow u = db.dt.Rows[0];
                    userR = Convert.ToString(u[1]);
                    passR = Convert.ToString(u[2]);
                    tipo  = Convert.ToInt16(u[3]);

                    if (user == userR && pass == passR && tipo == 1)
                    {
                        this.Hide();
                        AdminMDI mdiA = new AdminMDI();
                        mdiA.Show();
                    }

                    if (user == userR && pass == passR && tipo == 2)
                    {
                        this.Hide();
                        UserMDI mdiU = new UserMDI();
                        mdiU.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Datos incorrectos", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Limpiar.txb(this);
                    txbUser.Focus();
                }
            }
            else
            {
                MessageBox.Show("Debes de llenar ambos campos", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }