Anonymous Username - over 100 users

We have really weird issue, up until user 100 the username was in this format

anonymousxxx
e.g. anonymous10, anonymous55, anonymous100

However as soon as we reached over number 100 anonymous user accounts, they are now in this format:

9ab9441ad3316f5d2d35cd4807317cc
01c3b651778b7871a7640511daa8eb8

2 Likes

Think i can see why looking at this code, but it seems a bit short sighted to only allow 100 random users?

def self.find_available_username_based_on(name, allow_username = nil)
    name = fix_username(name)
    i = 1
    attempt = name
    **until attempt == allow_username || User.username_available?(attempt) || i > 100**
      suffix = i.to_s
      max_length = User.username_length.end - suffix.length - 1
      attempt = "#{name[0..max_length]}#{suffix}"
      i += 1
    end
    until attempt == allow_username || User.username_available?(attempt) || i > 200
      attempt = SecureRandom.hex[1..SiteSetting.max_username_length]
      i += 1
    end
    attempt
  end
4 Likes

Is this an actual bug @sam?

Surprisingly not the first time this has been reported:

Think that last report went misunderstood, too.

4 Likes

yeah, it hasn’t been fixed, so we have to change the name every 99 times :sleepy:

2 Likes

I suggest we fix this @tgxworld

1 Like

This is a tricky problem we need a different algorithm here.

Fixed per:

https://github.com/discourse/discourse/commit/a8fbb19e7c728f5f33d2b784530635791ea959e3

9 Likes

Thanks guys.

I was going to look at doing a change so when the username is ‘anonymous’ it works slightly different and checks for the last one created. But @sam 's solution seems a lot better.

4 Likes