Use Custom Function with mobile number and password

I am setting up authentication for my realm app, and I would like the user to be able to log in with a mobile number and password. So, it seems that Custom Function Authentication would be the best option for me.

However, I read your documentation, but I’m not sure how I would provide a user’s password. Do I just provide another field in the loginPayload object called “password”, and then store this password in the user’s document in the users collection? This doesn’t seem to be the right answer as it seems very insecure.

How would I go about setting up a function that lets the user log in with a mobile number and password?