Aboo Hurayrah narrated that the Prophet (sallallahu alayhi was sallam) said:
“A person follows (imitates) the religion of his friends, therefore let each one of you look at the one he befriends.” [Aboo Daawood, Tirmidhee, Ahmad, amongst others. See As-Saheehah #927]
Also, Aboo Moosaa Al-Ash’aree narrated that the Prophet (saw) said:
“The example of an evil companion is like an ironsmith. Either he burns your clothes or you smell a foul odor from him.” [Bukhaaree & Muslim]
Shaykh Ibn ‘Uthaymeen comments:
“… The youth has to to choose a good, righteous and intelligent person for his companion. He should evaluate the condition of the people before he befriends them by researching their condition and reputation. If they have good manners, sound religion, and a good reputation, then they are an object of a long-cherishing wish and profitable gain.
Therefore cling to them, otherwise beware! And stay away from people with evil and wicked character. This should be done so that one isn’t deceived by sweet speech and a beautiful outward appearance.
These attributes are a deception and a misguidance that the people of wickedness use in order to attract simple minded people and to increase their members. Also, they hide within these attributes the things that corrupt one’s behavior and manners.
The poet said it best:
Test the men you intend to brethren,
Look at their affairs closely.
If you gain one with piety and intellect,
Then cling to him happily.”
[Mushkilaat Ash-Shabaab, Pp. 31-32]