[App Server] - authenticating users

Hello,

I’m testing my app locally but I do not know how deal with users’ passwords. If I was using Anvil’s IDE, I could just click the little caret symbol in the Users service and set a password there just for testing.

With the open-source server, I can add users to the Users table (using --shell), but what is the best way to set a password, or allow the user to set it themselves?

I figured I’d use the login_with_form pop up to force a password reset but I’m told that I don’t have an SMTP server set up (I’m going to look into how to do this).

How do you all deal with this kind of thing?

Any insight or background info would be much appreciated.

Something like this should do the trick:

user = app_tables.users.get(email='meredydd@anvil.works')
pwhash_bin = bcrypt.hashpw(b'new password', bcrypt.gensalt(16))
user['password_hash'] = pwhash_bin.decode()
3 Likes

This is precisely what I was looking for!

Thank you very much!

Hmm,

Unfortunately the passwords are not being accepted by the app when I try to login in. The output doesn’t give me any related warnings (just the one about not being able to receive email), so that is good.

I’m just using test@test.com with the password “test” as a simple test.

My Users service is configured to allow MS login as well as email + password.

Oh! It seems that when I added a password and auto-created the password_hash column, my schema became invalid. I then used --auto-migrate without thinking and that deleted the password_hash column, preventing me from being able to log in.

If I run with --ignore-invalid-schema I can log in. Great!

Is there a way to tell the app to update the schema so that it includes these new columns?

Hi @alcampopiano
It seems that just sign up a new user and the password_hash column will be created.

Hi @alcampopiano,

Yep, that’s documented! The Anvil App Structure documentation in the App Server repo describes the app’s db_schema configuration.

Beauty thanks! I’ll give that a read.