code: func (s *Session) Login(ctx context.Context, creds apitypes.LoginCredential) error {
  	if !creds.Valid() {
  		return &apitypes.Error{
  			Type: apitypes.BadRequestError,
  			Err:  []string{"invalid login credentials provided"},
  		}
  	}
  
  	salt, loginToken, err := s.engine.client.Tokens.PostLogin(ctx, creds)
  	if err != nil {
  		return err
  	}
  
  	mechanism := loginToken.Body.Mechanism
  	var authToken *envelope.Token
  	switch mechanism {
  	case primitive.HMACAuth:
  		authToken, err = s.attemptEdDSAUpgrade(ctx, loginToken, salt, creds)
  	case primitive.EdDSAAuth:
  		authToken, err = s.attemptEdDSALogin(ctx, loginToken, salt, creds)
  	default:
  		err = &apitypes.Error{
  			Type: apitypes.InternalServerError,
  			Err:  []string{fmt.Sprintf("unrecognized auth mechanism: %s", mechanism)},
  		}
  	}
  	if err != nil {
  		return err
  	}
  
  	token := []byte(authToken.Body.Token)
  	self, err := s.engine.client.Self.Get(ctx, authToken.Body.Token)
  	if err != nil {
  		return err
  	}
  
  	s.engine.db.Set(self.Identity)
  	if self.Type == apitypes.UserSession {
  		s.engine.db.Set(self.Auth)
  	}
  
  	return s.engine.session.Set(self.Type, self.Identity, self.Auth, creds.Passphrase(), token)
  }
docs: // Login attempts to create a valid auth token to authorize http requests made
  // against the registry.