(ctx context.Context, password string, encrypt bool, encryptionKeyID, encryptionKey string)
| 327 | } |
| 328 | |
| 329 | func (u *User) SetPassword(ctx context.Context, password string, encrypt bool, encryptionKeyID, encryptionKey string) error { |
| 330 | if password == "" { |
| 331 | u.EncryptedPassword = nil |
| 332 | return nil |
| 333 | } |
| 334 | |
| 335 | pw, err := crypto.GenerateFromPassword(ctx, password) |
| 336 | if err != nil { |
| 337 | return err |
| 338 | } |
| 339 | |
| 340 | u.EncryptedPassword = &pw |
| 341 | if encrypt { |
| 342 | es, err := crypto.NewEncryptedString(u.ID.String(), []byte(pw), encryptionKeyID, encryptionKey) |
| 343 | if err != nil { |
| 344 | return err |
| 345 | } |
| 346 | |
| 347 | encryptedPassword := es.String() |
| 348 | u.EncryptedPassword = &encryptedPassword |
| 349 | } |
| 350 | |
| 351 | return nil |
| 352 | } |
| 353 | |
| 354 | // UpdatePassword updates the user's password. Use SetPassword outside of a transaction first! |
| 355 | func (u *User) UpdatePassword(tx *storage.Connection, sessionID *uuid.UUID) error { |
no test coverage detected