In Drupal 7, we can read the current user's custom data by:
global $user;
$user_obj = user_load($user->uid);
print_r($user_obj->data);
... and write by:
global $user;
$user_obj = user_load($user->uid);
user_save($user_obj, array('data' => array('key' => $value)));
Now in Drupal 8, we can read the current user's custom data by:
$user_data = \Drupal::service('user.data')->get('your_module_name', \Drupal::currentUser()->id(), 'key');
print_r($user_data);
... and write by:
\Drupal::service('user.data')->set('your_module_name', \Drupal::currentUser()->id(), 'key', $value);
thank you for your sharing
save time