MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / DoLogin

Method DoLogin

pkg/account/session/session.go:167–195  ·  view source on GitHub ↗

DoLogin performs the authentication using user id and password.

(ctx context.Context, userID, password string)

Source from the content-addressed store, hash-verified

165
166// DoLogin performs the authentication using user id and password.
167func (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}

Callers 2

TokenMethod · 0.80
LoginMethod · 0.80

Calls 9

ValidateContextMethod · 0.95
GetIdsMethod · 0.95
IsNotFoundFunction · 0.92
ValidateFunction · 0.92
PublishFunction · 0.92
TransactMethod · 0.65
GetUserMethod · 0.65
NewMethod · 0.65

Tested by

no test coverage detected