You are viewing a single comment's thread from:

RE: Today I Learned: The rules for a valid Steem account username (and how to find out stuff by reading sourcecode)

in #til6 years ago (edited)

EDIT: I finally decided to make my own guide on the rules. It includes segments and other parts that are not mentioned here but essential for understanding how usernames work:

https://steemit.com/programming/@cryptosharon/the-5-rules-of-a-valid-username-on-the-steem-blockchain-and-a-3-sbd-contest-to-make-an-account-name-validation-regex#comments


This is the current code I got from this Github entry. It was last updated on Sep 12, 2017. There are some slight differences (not including the language, since yours is hpp and this one is cpp). The main difference is that instead of using the number 3, it uses STEEM_MIN_ACCOUNT_NAME_LENGTH, which is also 3 most of the time, but the last position of . may vary depending on the implementation.

bool is_valid_account_name( const string& name )
{
#if STEEM_MIN_ACCOUNT_NAME_LENGTH < 3
#error This is_valid_account_name implementation implicitly enforces minimum name length of 3.
#endif

   const size_t len = name.size();
   if( len < STEEM_MIN_ACCOUNT_NAME_LENGTH )
      return false;

   if( len > STEEM_MAX_ACCOUNT_NAME_LENGTH )
      return false;

   size_t begin = 0;
   while( true )
   {
      size_t end = name.find_first_of( '.', begin );
      if( end == std::string::npos )
         end = len;
      if( end - begin < 3 )
         return false;
      switch( name[begin] )
      {
         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
         case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p':
         case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x':
         case 'y': case 'z':
            break;
         default:
            return false;
      }
      switch( name[end-1] )
      {
         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
         case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p':
         case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x':
         case 'y': case 'z':
         case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
         case '8': case '9':
            break;
         default:
            return false;
      }
      for( size_t i=begin+1; i<end-1; i++ )
      {
         switch( name[i] )
         {
            case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h':
            case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p':
            case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x':
            case 'y': case 'z':
            case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7':
            case '8': case '9':
            case '-':
               break;
            default:
               return false;
         }
      }
      if( end == len )
         break;
      begin = end+1;
   }
   return true;
}

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.029
BTC 56087.39
ETH 2965.10
USDT 1.00
SBD 2.15