users: lower max username length to 25 characters.
The median username length is 8 characters. The 99% percentile is 18 characters. The 99.9% percentile is 24 characters. About 750 users have a name more than 24 characters long. This doesn't do anything about existing users with long usernames. Note that this is the length in Unicode codepoints, not grapheme clusters. Some Unicode characters and emoji may be a single glyph but composed of multiple codepoints.
This commit is contained in:
@@ -11,7 +11,8 @@ class UserNameValidator < ActiveModel::EachValidator
|
||||
name = value
|
||||
|
||||
rec.errors.add(attr, "already exists") if User.find_by_name(name).present?
|
||||
rec.errors.add(attr, "must be 2 to 100 characters long") if !name.length.between?(2, 100)
|
||||
rec.errors.add(attr, "must be more than 1 character long") if name.length <= 1
|
||||
rec.errors.add(attr, "must be less than 25 characters long") if name.length >= 25
|
||||
rec.errors.add(attr, "cannot have whitespace or colons") if name =~ /[[:space:]]|:/
|
||||
rec.errors.add(attr, "cannot begin or end with an underscore") if name =~ /\A_|_\z/
|
||||
rec.errors.add(attr, "is not allowed") if name =~ Regexp.union(Danbooru.config.user_name_blacklist)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory(:user, aliases: [:creator, :updater]) do
|
||||
name { SecureRandom.uuid }
|
||||
name { SecureRandom.uuid.first(20) }
|
||||
password {"password"}
|
||||
level {20}
|
||||
last_logged_in_at {Time.now}
|
||||
|
||||
Reference in New Issue
Block a user