From b4620f561cc4c8bc71c217216d69c86e5cdbeec4 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 1 Mar 2022 20:58:49 -0600 Subject: [PATCH] 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. --- app/logical/user_name_validator.rb | 3 ++- test/factories/user.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/logical/user_name_validator.rb b/app/logical/user_name_validator.rb index e55687103..8d44cb064 100644 --- a/app/logical/user_name_validator.rb +++ b/app/logical/user_name_validator.rb @@ -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) diff --git a/test/factories/user.rb b/test/factories/user.rb index a9bbe1c77..6782bc73a 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -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}