Log a user in manually, get session?
For general entity, yes you can use entity.manager service.

For user entity, you can use \Drupal\user\Entity\User. However in your case, you are going to load user by username, this can't be done by User Entity class, you have to use entity.manager.

user_load_by_name will call something like this:

$entity_manager = Drupal::service('entity.manager');
$user = $entity_manager-&gt;storage('user')-&gt;loadByProperties(array('name' =&gt; $nusername));

I will just use this function if there is no reason to replace it.
Use the session_manager service.

$session_manager = Drupal::service('session_manager');
$session_id = $session_manager-&gt;getId();