code: func generateUsername(r *http.Request, firstname, lastname string) (string, error) {
  	counter := 0
  	var username string
  	for _, r := range firstname {
  		if unicode.IsSpace(r) {
  			continue
  		}
  		username += string(unicode.ToLower(r))
  	}
  	username += "_"
  	for _, r := range lastname {
  		if unicode.IsSpace(r) {
  			continue
  		}
  		username += string(unicode.ToLower(r))
  	}
  	username += "_"
  	userMgr := user.NewManager(r)
  
  	count, err := userMgr.GetPendingRegistrationsCount()
  	if err != nil {
  		return "", err
  	}
  	log.Debug("count", count)
  	if count >= MAX_PENDING_REGISTRATION_COUNT {
  		return "", errors.New("Max amount of pending registrations reached")
  	}
  
  	orgMgr := organization.NewManager(r)
  	exists := true
  	for exists {
  		counter++
  		var err error
  		exists, err = userMgr.Exists(username + strconv.Itoa(counter))
  		if err != nil {
  			return "", err
  		}
  		if !exists {
  			exists = orgMgr.Exists(username + strconv.Itoa(counter))
  		}
  	}
  	username = username + strconv.Itoa(counter)
  	return username, nil
  }
docs: // generateUsername generates a new username