Ash Way of Doing Password Hashing and Storage for Phoenix.
So
mix phx.gen.auth
will give you the some of the following in your_app/lib/your_app/accounts/user.ex
:
This seems like the most straightforward way when starting a Phoenix app that has users. Phoenix generates a lot of other private functions for user auth, so for Ash do you create a new module to reference and use similar functions for validate
/change
blocks?11 Replies
So this is what I have so far that I believe is how it should be done in Ash:
there was a repo from a while ago (wont work out of the box with newest ash)
https://github.com/ash-project/example_with_auth
I'd recommend you use ash-authentication tbh
https://github.com/ash-project/example_with_auth/blob/main/lib/example_with_auth/accounts/resources/user/changes/hash_password.ex
Ah, so what's here? https://ash-hq.org/docs/guides/ash_authentication_phoenix/latest/getting-started-with-ash-authentication-phoenix
Ash HQ
Guide: Getting Started With Ash Authentication Phoenix
Read the "Getting Started With Ash Authentication Phoenix" guide on Ash HQ
yeah this is the recommended way now
Yeah, ideally you'd use ash_authentication, but the validation code you mentioned above looks fine. Well, actually, you'd want only a single regex
that would fail on the first validation not matching. I.e
A
would not be allowedMakes sense. I'm terrible at regex so I'll have to remind myself how it would work for a password. I guess my one question is what exactly would I need to do in order to have ash_authentication use argon2 for hashing passwords?
Found 2 results in ash_authentication:
* AshAuthentication.Strategy.Password: https://ash-hq.org/docs/module/ash_authentication/3.9.5/ashauthentication-strategy-password
* t: https://ash-hq.org/docs/module/ash_authentication/3.9.5/ashauthentication-strategy-password#type-t-0
You'd need to implement a
hash_provider
and configure it in the password strategy
Ah okay, I think I'm following. What are the advantages to using the ash_authentication as opposed to doing it yourself?
Mostly just flexibility?
There is also ash authentication phoenix
Basically just not having to do it yourself.
And we are adding features
Oh okay, as an example, it's abstracting some of the CRUD actions you'd have to do for creating/updating a user password, right? Because I have the
create :signup
but I'd also need an update
action for resetting the password etc.
Oh okay, I looked at the ash_hq
project and it's making more sense to me now.