but I forgot the password which was used.
Check your Apple ID via your email box, see this Apple article: If you forgot your Apple ID
If you forgot your Apple ID email address or phone number - Apple Support
OR see -> Having trouble signing in?
https://iforgot.apple.com/password/verify/appleid
Then see this Apple article: What to do after you change your Apple ID or password
What to do after you change your Apple ID or password - Apple Support
Then see -> What to do before you sell, give away, or trade in your iPhone, iPad, or iPod touch
What to do before you sell, give away, or trade in your iPhone, iPad, or iPod touch - Apple Support
Then chek, see this Apple article: Check your Apple ID device list to see where you're signed in
Check your Apple ID device list to see where you're signed in - Apple Support
Remove the iPhone X from your list.
Then your friend can sign in with his Apple ID.