Anonymous Username - over 100 users

(Jono Brain) #1

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

1 Like
(Jono Brain) #2

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
(Jeff Atwood) #3

Is this an actual bug @sam?

(Stephen) #4

Surprisingly not the first time this has been reported:

Think that last report went misunderstood, too.

4 Likes
(Lisbeth Wu) #5

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

2 Likes
(Jeff Atwood) #6

I suggest we fix this @tgxworld

1 Like
(Sam Saffron) #7

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

Fixed per:

6 Likes
(Jono Brain) #8

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.

3 Likes