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 ?
Stephen
(Stephen)
May 16, 2019, 5:13am
4
Surprisingly not the first time this has been reported:
Hi, this is Lisbeth from Taiwan.
We use Traditional Chinese version discourse here, and we found this bug when our anonymous username become random hex which looks creepy for friendly users LOL.
Our first 100 anonymous username are something like 1111, 1112…111100, after 111100, it will become random hex.
So I keep digging the source code, and see that anonymous user name use a user_name_suggester.suggest, it will put Anonymous in Chinese (匿名) these two words into the suggester, when it go th…
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
2 Likes
I suggest we fix this @tgxworld
1 Like
sam
(Sam Saffron)
May 16, 2019, 7:16am
7
This is a tricky problem we need a different algorithm here.
Fixed per:
committed 07:15AM - 16 May 19 UTC
Previously username suggester would give up after 100 attempts at getting
a user… name and fallback to random string.
This amends the logic so we do all the work of figuring out a good username
in SQL and avoids a large amount of queries in cases where a lot of usernames
were used up.
This corrects an issue on sites with large numbers of anon users
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