| 578 | } |
| 579 | |
| 580 | func (u *UserRecord) SetPassword(pw string) error { |
| 581 | |
| 582 | validation := configs.GetValidationConfig() |
| 583 | |
| 584 | if len(pw) < int(validation.PasswordSizeMin) || len(pw) > int(validation.PasswordSizeMax) { |
| 585 | return fmt.Errorf("password must be between %d and %d characters long", validation.PasswordSizeMin, validation.PasswordSizeMax) |
| 586 | } |
| 587 | |
| 588 | hash, err := bcrypt.GenerateFromPassword([]byte(pw), bcrypt.DefaultCost) |
| 589 | if err != nil { |
| 590 | return fmt.Errorf("failed to hash password: %w", err) |
| 591 | } |
| 592 | u.Password = string(hash) |
| 593 | return nil |
| 594 | } |
| 595 | |
| 596 | func (u *UserRecord) ConnectionId() uint64 { |
| 597 | return u.connectionId |