Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

482
Vistas
What datatype would I use to store a sha265 password in a Postgres database

Solved, thank you for those asking me what error it was:

pq: invalid byte sequence for encoding "UTF8": 0xe3 0xb0 0xc4

This meant I needed to store the password as bytea

If I want to insert a sha265 password in a Postgres database what datatype would I use. Text does not seem to be working for me.

Here is the line of code with the query

query := fmt.Sprintf("INSERT INTO users(username,password) VALUES('%s','%s') returning uid;", username, hashedPassword)

For those wondering here is the Go code. Like I said though, it works fine as long as the password isn't encrypted so I don't think this will be of much help

func hashPassword(password string) string {
    h := sha256.New()
    passwordBytes := []byte(password)
    passwordHashed := h.Sum(passwordBytes)
    return string(passwordHashed)
}

func createUser(username string, password string, passwordConfirm string) bool {
    dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable",
    DB_USER, DB_PASSWORD, DB_NAME)
    db, err := sql.Open("postgres", dbinfo)
    checkErr(err)
    defer db.Close()

    hashedPassword := hashPassword(password)
    hashedPasswordConfirm := hashPassword(passwordConfirm)


    if hashedPassword != hashedPasswordConfirm {
        return false
    }

    var lastInsertId int
    query := fmt.Sprintf("INSERT INTO users(username,password) VALUES('%s',$trick$%s$trick$) returning uid;", username, hashedPassword)
    err = db.QueryRow(query).Scan(&lastInsertId)

    fmt.Println(lastInsertId)

    if err != nil {
        return false;
    }
    return true;
}

Here is the table declaration

CREATE TABLE users
(
    uid SERIAL,
    username text NOT NULL UNIQUE,
    password text NOT NULL,
    weekly_goals bytea,
    CONSTRAINT users_pkey PRIMARY KEY (uid)
) WITH (OIDS=FALSE);
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda