public Boolean ingreso_usuario(string username, string password)
        {
            funciones funcion = new funciones();

            password = funcion.md5_encode(password);

            int length = 0;

            bool response = false;

            Conexion conexion = new Conexion();

            conexion.abrir();
            DataTable dt = new DataTable();

            conexion.comando.CommandText = "select id_usuario from usuarios where usuario='" + username + "' and clave='" + password + "'";
            dt.Load(conexion.comando.ExecuteReader());
            length = dt.Rows.Count;
            conexion.cerrar();

            if (length >= 1)
            {
                response = true;
            }
            else
            {
                response = false;
            }

            return(response);
        }
        public bool cambiar_contraseña(String username, String new_password)
        {
            Boolean   respuesta = false;
            funciones funcion   = new funciones();
            String    password  = funcion.md5_encode(new_password);

            String sql = "update usuarios set clave='" + password + "' where usuario='" + username + "'";

            try
            {
                Conexion conexion = new Conexion();
                conexion.abrir();
                conexion.comando.CommandText = sql;
                conexion.comando.ExecuteNonQuery();
                conexion.cerrar();
                respuesta = true;
            }
            catch
            {
                respuesta = false;
            }
            return(respuesta);
        }
예제 #3
0
        private void grabar()
        {
            if (validar())
            {
                int tipo = 0;

                if (cmbTipo.SelectedIndex == 1)
                {
                    tipo = 1;
                }
                else
                {
                    tipo = 2;
                }

                Usuarios  u         = new Usuarios();
                funciones funciones = new funciones();

                String password = funciones.md5_encode(txtPassword.Text);

                u.pNombre         = txtUsuario.Text;
                u.pPassword       = password;
                u.pTipo           = tipo;
                u.pFecha_registro = funcion.fecha_del_dia();

                String sql = "";

                if (nuevo)
                {
                    sql = "insert into usuarios values('" + u.pNombre + "','" + u.pPassword + "'," + u.pTipo + ",'" + u.pFecha_registro + "')";
                }
                else
                {
                    sql = "update usuarios set tipo=" + tipo + " where usuario='" + u.pNombre + "'";
                }

                //datos.Actualizar(sql);
                //MessageBox.Show(sql);

                bool grabar_ready = false;

                if (datos.comprobar_existencia_usuario_crear(u.pNombre))
                {
                    grabar_ready = false;
                }
                else
                {
                    grabar_ready = true;
                }

                if (grabar_ready)
                {
                    if (datos.CargarConsulta(sql))
                    {
                        if (nuevo)
                        {
                            MessageBox.Show("Registro agregado");
                            tsStatus.Text = "[+] Registro agregado";
                            this.Refresh();
                        }
                        else
                        {
                            MessageBox.Show("Registro actualizado");
                            tsStatus.Text = "[+] Registro actualizado";
                            this.Refresh();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Ha ocurrido un error en la base de datos");
                        tsStatus.Text = "[-] Ha ocurrido un error en la base de datos";
                        this.Refresh();
                    }
                }
                else
                {
                    MessageBox.Show("El usuario " + u.pNombre + " ya existe");
                    tsStatus.Text = "[-] El usuario " + u.pNombre + " ya existe";
                    this.Refresh();
                }

                cargarUsuarios();
                limpiar();
            }
        }