Connect automatically on wifi

Can I programmatically connect to a hotspot wifi without user intervention?

I have the password stored in an app and the clients will not able to see it.

Since this is in the Rails forum I'll assume you're talking about a
website
using JavaScript.
The short answer is "No". JavaScript is sandboxed to avoid giving
viruses precisely the kind of control you're asking about. Altering a
user's network settings via a website would be a very dangerous road to
go down.