Hashing new password on update
Using postgres' pgcrypt
This commit is contained in:
@@ -49,6 +49,7 @@ func HandleUpdateUser(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
for i := 0; i < val.NumField(); i++ {
|
||||
field := val.Field(i)
|
||||
fieldname := typ.Field(i).Name
|
||||
|
||||
tag := typ.Field(i).Tag.Get("bun")
|
||||
if tag == "" {
|
||||
@@ -57,7 +58,11 @@ func HandleUpdateUser(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Only add fields that are non-nil and non-zero
|
||||
if field.IsValid() && !field.IsNil() && !field.IsZero() {
|
||||
updateQuery.Set(fmt.Sprintf("%s = ?", strings.Split(tag, ",")[0]), field.Interface())
|
||||
if fieldname == "Password" {
|
||||
updateQuery.Set(fmt.Sprintf("%s = crypt(?, gen_salt('bf'))", strings.Split(tag, ",")[0]), field.Interface())
|
||||
} else {
|
||||
updateQuery.Set(fmt.Sprintf("%s = ?", strings.Split(tag, ",")[0]), field.Interface())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user