Enforce maximum password limit
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -48,7 +48,8 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
ErrInvalidPassword struct {
|
ErrInvalidPassword struct {
|
||||||
length int
|
minLength int
|
||||||
|
maxLength int
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrInvalidFullName struct {
|
ErrInvalidFullName struct {
|
||||||
@@ -145,7 +146,7 @@ func (e ErrInvalidEmail) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrInvalidPassword) Error() string {
|
func (e ErrInvalidPassword) Error() string {
|
||||||
return fmt.Sprintf("invalid password: the length must be at least %d characters", e.length)
|
return fmt.Sprintf("invalid password: the length must be between %d and %d characters", e.minLength, e.maxLength)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrInvalidFullName) Error() string {
|
func (e ErrInvalidFullName) Error() string {
|
||||||
@@ -251,8 +252,8 @@ func (s Service) SignUp(
|
|||||||
return nil, nil, &ErrInvalidEmail{email}
|
return nil, nil, &ErrInvalidEmail{email}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(password) < 8 {
|
if len(password) < 8 || len(password) > 128 {
|
||||||
return nil, nil, &ErrInvalidPassword{len(password)}
|
return nil, nil, &ErrInvalidPassword{minLength: 8, maxLength: 128}
|
||||||
}
|
}
|
||||||
|
|
||||||
if fullName == "" {
|
if fullName == "" {
|
||||||
@@ -348,6 +349,10 @@ func (s Service) SignIn(
|
|||||||
UpdatedAt: now,
|
UpdatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(password) < 8 || len(password) > 128 {
|
||||||
|
return nil, nil, &ErrInvalidPassword{minLength: 8, maxLength: 128}
|
||||||
|
}
|
||||||
|
|
||||||
err := s.pg.WithTx(
|
err := s.pg.WithTx(
|
||||||
ctx,
|
ctx,
|
||||||
func(tx pg.Conn) error {
|
func(tx pg.Conn) error {
|
||||||
@@ -750,8 +755,8 @@ func (s Service) ConfirmInvitation(ctx context.Context, tokenString string, pass
|
|||||||
return nil, fmt.Errorf("cannot validate organization invitation token: %w", err)
|
return nil, fmt.Errorf("cannot validate organization invitation token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(password) < 8 {
|
if len(password) < 8 || len(password) > 128 {
|
||||||
return nil, &ErrInvalidPassword{len(password)}
|
return nil, &ErrInvalidPassword{minLength: 8, maxLength: 128}
|
||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@@ -855,8 +860,8 @@ func (s Service) ResetPassword(ctx context.Context, tokenString string, newPassw
|
|||||||
return fmt.Errorf("cannot validate password reset token: %w", err)
|
return fmt.Errorf("cannot validate password reset token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(newPassword) < 8 {
|
if len(newPassword) < 8 || len(newPassword) > 128 {
|
||||||
return &ErrInvalidPassword{length: 8}
|
return &ErrInvalidPassword{minLength: 8, maxLength: 128}
|
||||||
}
|
}
|
||||||
|
|
||||||
hashedPassword, err := s.hp.HashPassword([]byte(newPassword))
|
hashedPassword, err := s.hp.HashPassword([]byte(newPassword))
|
||||||
|
|||||||
Reference in New Issue
Block a user