Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
Go & Javascript secure authentication

I'm currently signing users (authenticating) from the frontend, and making requests to the backend to sign up the user(save data in the database). I realize i cannot completely prevent this, but i don't want my API(signup) to be abused.

Go:

func SignIn(w http.ResponseWriter, r *http.Request) {
    params := mux.Vars(r)
    u_ip := base64Decode((params["u_ip"]))
    u_wallet := base64Decode(string(params["u_wallet"]))
    u_password := base64Decode(params["u_pass"])

    u_addr := strings.TrimPrefix(u_wallet, "0x")
    u_addr_temp := u_addr[0:7]
    for rowExists("select 1 from users where position(user_addr in $1)>0", u_addr_temp) {
        randInt := rand.Intn(5)
        u_addr_temp = u_addr[randInt : randInt+7]
    }

    sqlStatement := `INSERT INTO users (ip, user_addr, user_wallet, user_pass)
     VALUES($1, $2, $3, $4) returning id;`
    id := 0
    db := opendb()
    err := db.QueryRow(sqlStatement, u_ip, u_addr_temp, u_wallet, u_password).Scan(&id)
    if err != nil {
        panic(err)
    }
    w.WriteHeader(http.StatusCreated)
    w.Header().Set("Content-Type", "application/json")
    resp := make(map[string]string)
    resp["message"] = string(id) + "-" + string(u_addr_temp)
    jsonResp, err := json.Marshal(resp)
    if err != nil {
        log.Fatalf("Json Err. Err: %s", err)
    }
    w.Write(jsonResp)
}

Javascript:

              const u_wallet = window.btoa(result);
              const u_password = window.btoa(password.toString());
              await fetch(
                `http://localhost:8080/sign/${u_wallet}&${u_password}`,
                {
                  method: "POST",
                }
              )
                .then((response) => response.json())
                .then((data) => console.log(data));
            })();

You can see users can call http://localhost:8080/sign/${u_wallet}&${u_password} replace the wallet, and password (Base64 encoded) And GoLang will automatically create the row(in the database).

Go CORS:

    c := cors.New(cors.Options{
        AllowedOrigins:   []string{"*"},
        AllowCredentials: true,
    })
    handler := c.Handler(router)

I can define Allowed Origins as strict-origin-when-cross-origin, but users will use the devtools console(JS). My question isn't sending the data(safely), but how to communicate from the frontend and backend, and try and block users from calling the API.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda