Login with email or username implementation

You probably don’t wanna allow special characters in username. Look at how twitter, Facebook and other big sites do it. If you limit username strictly to alphanumeric then its just matter of checking @ in string to distinguish between email and username.