safeguard against integer user ids and centralize username matching logic