DoLogin performs the authentication using user id and password.
(ctx context.Context, userID, password string)
| 165 | |
| 166 | // DoLogin performs the authentication using user id and password. |
| 167 | func (s *Session) DoLogin(ctx context.Context, userID, password string) error { |
| 168 | ids := &ttnpb.UserIdentifiers{UserId: userID} |
| 169 | if err := ids.ValidateContext(ctx); err != nil { |
| 170 | return err |
| 171 | } |
| 172 | var user *ttnpb.User |
| 173 | err := s.Store.Transact(ctx, func(ctx context.Context, st Store) (err error) { |
| 174 | user, err = st.GetUser( |
| 175 | ctx, |
| 176 | ids, |
| 177 | []string{"password"}, |
| 178 | ) |
| 179 | return err |
| 180 | }) |
| 181 | if err != nil { |
| 182 | if errors.IsNotFound(err) { |
| 183 | return errIncorrectPasswordOrUserID.New() |
| 184 | } |
| 185 | return err |
| 186 | } |
| 187 | region := trace.StartRegion(ctx, "validate password") |
| 188 | ok, err := auth.Validate(user.Password, password) |
| 189 | region.End() |
| 190 | if err != nil || !ok { |
| 191 | events.Publish(evtUserLoginFailed.NewWithIdentifiersAndData(ctx, user.GetIds(), nil)) |
| 192 | return errIncorrectPasswordOrUserID.New() |
| 193 | } |
| 194 | return nil |
| 195 | } |
no test coverage detected