|
6 | 6 |
|
7 | 7 | "github.com/shellhub-io/shellhub/cli/pkg/inputs" |
8 | 8 | "github.com/shellhub-io/shellhub/pkg/clock" |
| 9 | + "github.com/shellhub-io/shellhub/pkg/hash" |
9 | 10 | "github.com/shellhub-io/shellhub/pkg/models" |
10 | 11 | ) |
11 | 12 |
|
@@ -40,23 +41,18 @@ func (s *service) UserCreate(ctx context.Context, input *inputs.UserCreate) (*mo |
40 | 41 | } |
41 | 42 | } |
42 | 43 |
|
43 | | - password, err := models.HashUserPassword(input.Password) |
| 44 | + pwdDigest, err := hash.Do(input.Password) |
44 | 45 | if err != nil { |
45 | 46 | return nil, ErrUserPasswordInvalid |
46 | 47 | } |
47 | 48 |
|
48 | | - // TODO: validate this at cmd layer |
49 | | - if ok, err := s.validator.Struct(password); !ok || err != nil { |
50 | | - return nil, ErrUserPasswordInvalid |
51 | | - } |
52 | | - |
53 | 49 | user := &models.User{ |
54 | | - Origin: models.UserOriginLocal, |
55 | | - UserData: userData, |
56 | | - Password: password, |
57 | | - Status: models.UserStatusConfirmed, |
58 | | - CreatedAt: clock.Now(), |
59 | | - MaxNamespaces: MaxNumberNamespacesCommunity, |
| 50 | + Origin: models.UserOriginLocal, |
| 51 | + UserData: userData, |
| 52 | + PasswordDigest: pwdDigest, |
| 53 | + Status: models.UserStatusConfirmed, |
| 54 | + CreatedAt: clock.Now(), |
| 55 | + MaxNamespaces: MaxNumberNamespacesCommunity, |
60 | 56 | Preferences: models.UserPreferences{ |
61 | 57 | AuthMethods: []models.UserAuthMethod{models.UserAuthMethodLocal}, |
62 | 58 | }, |
@@ -117,17 +113,12 @@ func (s *service) UserUpdate(ctx context.Context, input *inputs.UserUpdate) erro |
117 | 113 | return ErrUserNotFound |
118 | 114 | } |
119 | 115 |
|
120 | | - password, err := models.HashUserPassword(input.Password) |
| 116 | + pwdDigest, err := hash.Do(input.Password) |
121 | 117 | if err != nil { |
122 | 118 | return ErrUserPasswordInvalid |
123 | 119 | } |
124 | 120 |
|
125 | | - // TODO: validate this at cmd layer |
126 | | - if ok, err := s.validator.Struct(password); !ok || err != nil { |
127 | | - return ErrUserPasswordInvalid |
128 | | - } |
129 | | - |
130 | | - if err := s.store.UserUpdate(ctx, user.ID, &models.UserChanges{Password: password.Hash}); err != nil { |
| 121 | + if err := s.store.UserUpdate(ctx, user.ID, &models.UserChanges{Password: pwdDigest}); err != nil { |
131 | 122 | return ErrFailedUpdateUser |
132 | 123 | } |
133 | 124 |
|
|
0 commit comments