My iphone 5 keeps freezing when i try to text?

It started yesterday whenever i try to use the keyboard it freezes and restarts itself i read online that i should restore it but whenever i connect my phone to the laptop it says i should press "trust" on the iphone but i have a password and i can't unlock it cause it freezes when i try to use the password. And my power button isn't working. How do i skip the trust thing? Can i skip it? Or should i just take it somewhere to fix it?

Added (1). it freezes when i try to use the keyboard**

If you power buntton is broken this won't work (not sure if you meant it just isn't responding because of the glitch). Try holding the home button and power button at the same time until it reboots (about 10 seconds). Then see if you can use the keyboard. Once you figure out how to get back into the phone I would check to see if you are running out not memory. Settings/general/about.

You could try logging into icloud and forcing a reset of the iPhone through there if you have everything backed up already.

Otherwise you may need for the power to run down until it turns off and it may get you past the issue.

Lesson learned: Don't buy Apple products.