Ejemplo n.º 1
0
        public QueryResult BuscarUsuario(string user, string password)
        {
            QueryResult Resultado;
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GD1C2014"].ConnectionString))
            {
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                //verificar la tabla correcta Y el select
                command.CommandText = @"select  from ESQ.usuario where USER=@user and PASSWORD = @password";

                command.Parameters.Add("@user", SqlDbType.NVarChar);
                command.Parameters.Add("@password", SqlDbType.NVarChar);

                command.Parameters["@user"].Value = user;
                command.Parameters["@password"].Value = password;

                SqlDataReader Reg = command.ExecuteReader();
                if (Reg.Read())
                {
                    if (Convert.ToInt32(Reg[1]) < 3)
                    {
                        Resultado = new QueryResult() { correct = true, ID = Convert.ToInt32(Reg[0]), mensaje = "Bienvenido Datos correctos" };

                        QueryResult salida = resetLogin(Convert.ToInt32(Reg[0]));

                        if (salida.correct == false)
                        {
                            Resultado.correct = salida.correct;
                            Resultado.mensaje = Resultado.mensaje + '\n' + salida.mensaje;
                        }
                    }
                    else
                    {
                        Resultado = new QueryResult() { correct = false, mensaje = "Usuario Inhabilitado" };
                    }
                }
                else
                {
                    Resultado = new QueryResult() { correct = false, mensaje = "Usuario/Contraseña invalidos" };

                    if (Reg.HasRows)
                    {
                        QueryResult salida = failLogin(Convert.ToInt32(Reg[1]));

                        if (salida.correct == false)
                        {
                            Resultado.mensaje = Resultado.mensaje + '\n' + salida.mensaje;
                        }
                    }
                }

            }
            return Resultado;
        }
Ejemplo n.º 2
0
        private QueryResult resetLogin(Int32 user_id)
        {
            QueryResult Resultado = new QueryResult();

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GD2013"].ConnectionString))
            {
                connection.Open();
                SqlCommand command = connection.CreateCommand();
                //Realizar el update
                command.CommandText = @"update tabla
                                       set campo=0
                                           where usuario=@user_id";

                command.Parameters.Add("@userId", SqlDbType.Int);
                command.Parameters["@userId"].Value = user_id;

                Int32 Reg = command.ExecuteNonQuery();
                if (Reg > 0) {
                    Resultado.correct = true;
                } else {
                    Resultado.correct = false;
                    Resultado.mensaje = "No se puedo resetear los login's del usuario";
                }

            }
            return Resultado;
        }