Notes/user.go

35 lines
602 B
Go
Raw Normal View History

2023-07-20 10:47:49 +02:00
package main
2024-01-05 20:00:02 +01:00
/*
2023-07-20 10:47:49 +02:00
func (session Session) UpdatePassword(currPass, newPass string) (ok bool, err error) {
var result sql.Result
var rowsAffected int64
result, err = db.Exec(`
UPDATE public.user
SET
password = password_hash(
2024-01-05 20:00:02 +01:00
/ salt in hex /
2023-07-20 10:47:49 +02:00
ENCODE(gen_random_bytes(16), 'hex'),
2024-01-05 20:00:02 +01:00
/ password /
2023-07-20 10:47:49 +02:00
$1::bytea
)
WHERE
id = $2 AND
password=password_hash(SUBSTRING(password FROM 1 FOR 32), $3::bytea)
RETURNING id
`,
2023-12-28 08:08:59 +01:00
newPass,
session.UserID,
currPass,
2023-07-20 10:47:49 +02:00
)
if rowsAffected, err = result.RowsAffected(); err != nil {
return
}
return rowsAffected > 0, nil
}
2024-01-05 20:00:02 +01:00
*/