content: /*
   * Solo - A small and beautiful blogging system written in Java.
   * Copyright (c) 2010-present, b3log.org
   *
   * Solo is licensed under Mulan PSL v2.
   * You can use this software according to the terms and conditions of the Mulan PSL v2.
   * You may obtain a copy of Mulan PSL v2 at:
   *         http://license.coscl.org.cn/MulanPSL2
   * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
   * See the Mulan PSL v2 for more details.
   */
  package org.b3log.solo.model;
  
  import org.apache.commons.lang3.StringUtils;
  
  /**
   * This class defines ext of user model relevant keys.
   *
   * @author <a href="http://88250.b3log.org">Liang Ding</a>
   * @version 1.3.0.0, Feb 8, 2019
   * @see org.b3log.latke.model.User
   * @since 0.4.1
   */
  public final class UserExt {
  
      /**
       * Key of user avatar.
       */
      public static final String USER_AVATAR = "userAvatar";
  
      /**
       * Max user name length.
       */
      public static final int MAX_USER_NAME_LENGTH = 64;
  
      /**
       * Min user name length.
       */
      public static final int MIN_USER_NAME_LENGTH = 1;
  
      /**
       * Key of user B3 key.
       */
      public static final String USER_B3_KEY = "userB3Key";
  
      /**
       * Key of GitHub open id.
       */
      public static final String USER_GITHUB_ID = "userGitHubId";
  
      /**
       * Checks whether the specified name is invalid.
       * <p>
       * A valid user name:
       * <ul>
       * <li>length [1, 64]</li>
       * <li>content {a-z, A-Z, 0-9, -}</li>
       * <li>Not contains "admin"/"Admin"</li>
       * </ul>
       * </p>
       *
       * @param name the specified name
       * @return {@code true} if it is invalid, returns {@code false} otherwise
       */
      public static boolean invalidUserName(final String name) {
          final int length = name.length();
          if (length < MIN_USER_NAME_LENGTH || length > MAX_USER_NAME_LENGTH) {
              return true;
          }
  
          char c;
          for (int i = 0; i < length; i++) {
              c = name.charAt(i);
              if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || '-' == c) {
                  continue;
              }
  
              return true;
          }
  
          return StringUtils.containsIgnoreCase(name, "admin");
      }
  
      /**
       * Private constructor.
       */
      private UserExt() {
      }
  }
  