HIVE username Regex checker

in HiveDevs2 years ago (edited)

hive_username_regex_checker


After being busy with work, then late because of Covid, and then late with work again, I found time to put into practice something I had talked about a few months earlier with [@]stoodkev.

Some time ago I spent a lot of time trying to find a good HIVE username Regex. What I think I did with the following one:

^(?=.{3,16}$)[a-z]([0-9a-z]|[0-9a-z\-](?=[0-9a-z])){2,}([\.](?=[a-z][0-9a-z\-][0-9a-z\-])[a-z]([0-9a-z]|[0-9a-z\-](?=[0-9a-z])){1,}){0,}$

You can test it and see it also on regex101

During this conversation [@]stoodkev suggested going further by testing all usernames already created on HIVE, which I must admit was an excellent suggestion.

So I started to build a HIVE username Regex checker in NodeJS/Typescript to test the Regex on all HIVE usernames already created. I also took the opportunity to include a random username generation function to test them (more info in the tech part).

You can find it on this Github repo: https://github.com/Mintrawa/hive-username-regex

The result is very interesting, after testing the 2,409,078 username of the HIVE blockchain my Regex failed 11 times

screenshot_2022_06_29_181658

{
  "last_username": "zzzzzzzzzzzzzzzz",
  "nb_tested": 2409078,
  "nb_passed": 2409067,
  "nb_error": 11,
  "list_not_passed": [
    "block--chains",
    "bors--nft",
    "huobi--pro",
    "kws--squitoz",
    "m--b",
    "morad--t",
    "ms--0315",
    "nature--refactor",
    "sex--addict",
    "steem--cn",
    "xn--hg3bi2h"
  ]
}

screenshot_2022_06_29_181603

It seems that we can create a username with "--" while for me it was not possible 🤔 I think I'm not the only one to think so since Ecency, Peakd, HiveOnBoard, Inji also prevent it.

For the answer to the "--", I invite you to read the latest post 👉 HIVE username Regex | Round 2


Tech part


The HIVE username Regex checker

An interactive command-line user interface (inquirer) allowing you to enter your own Regex with the possibility to test all existing HIVE usernames or an auto-generated file containing a list of usernames (Array of strings).

Getting Started

Installation

clone the repository

$  git clone https://github.com/Mintrawa/hive-username-regex

install the librairie

$  cd hive-username-regex && npm install

Configuration

Copy the ./config/default.config.json file to ./config/config.json and add/modify the values in the copied file.

  • HIVE_NODES_LIST: list of HIVE blockchain rpc node you want to use (failover)
  • HIVE_NODE_TIMEOUT: timeout for HIVE blockchain rpc node (ms)
  • NUMBER_USERNAME_TO_GENERATE: number of username to generate (file tester)

Start the tester

use the command npm start and answer the question

? Run in debug mode? (y/N)

if you want more information through the console (default false)

? What username regex would you like to test?

Put one or use the default (cf: )

? Reinit last HIVE blockchain results? (y/N)

if you want to reset the results of the previous test against all the usernames of the HIVE blockchain (default false)

? Test all usernames in the HIVE blockchain? (Y/n)

if you want to test your regex against all the usernames of the HIVE blockchain (default true)

? Reinit last File results? (y/N)

if you want to reset the results of the previous test against all the usernames of the auto-generated file (default false)

? Generate a username file? (y/N)

if you want to generate a usernames.json file (random username) in ./config/ directory (default false)

? Test the file generated? (y/N)

if you want to test your regex against all the usernames of the auto-generated username file, the number depending on the value of NUMBER_USERNAME_TO_GENERATE in config.json file (default false)

Results

The results are located in results folder. For the regex against all the usernames of the HIVE blockchain, the file is blockchain.json and for the regex against all the usernames of the auto-generated username the file is file.json

ex of results:

{
  "last_username": "zzzzzzzzzzzzzzzz",
  "nb_tested": 33044,
  "nb_passed": 33044,
  "nb_error": 0,
  "list_not_passed": []
}

The auto generated username file

Usage of chanceJS to create random username

let username = this.chance.character({ pool: 'abcdefghijklmnopqrstuvwxyz0123456789.-' })
for (let index = 0; index < this.chance.integer({ min: 3, max: 16 }); index++) {
  username += this.chance.character({ pool: 'abcdefghijklmnopqrstuvwxyz0123456789.-' })
}

Contributing

Pull requests for new features, bug fixes, and suggestions are welcome!

sep.png

@mintrawa :)


Thanks for your support and trust as a
HIVE block producer (witness active rank 72)

My HIVE block producer (witness) introduction post

sep.png


Vote for my HIVE block producer account (witness): click here (via HiveSigner)


Original Cover Photo of this post by Daniele Levis Pelusi on Unsplash

Sort:  

Congratulations @mintrawa! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You received more than 3000 upvotes.
Your next target is to reach 3250 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Hive Power Up Day - July 1st 2022
NFT for peace - Thank you for your continuous support


The rewards earned on this comment will go directly to the people( @mintrawa ) sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.