get user id from username or email without logging in
You can load the user with loadByProperties():

$users = \Drupal::entityTypeManager()-&gt;getStorage('user')
  -&gt;loadByProperties(['mail' =&gt; $mail]);
$user = reset($users);
if ($user) {
  $uid = $user-&gt;id();
  $rids = $user-&gt;getRoles();
}