Phauxth v0.8.1 Phauxth.Confirm.DB_Utils
User confirmation helper functions for use with Ecto.
Summary
Functions
Add a confirmation token to the user changeset
Add a reset token to the user changeset
Function used to check if a confirmation token has expired
Add the password hash for the new password to the database
Change the ‘confirmed_at’ value in the database to the current time
Functions
Add a confirmation token to the user changeset.
Add the following three entries to your user schema:
field :confirmation_token, :string
field :confirmation_sent_at, Ecto.DateTime
field :confirmed_at, Ecto.DateTime
Examples
In the following example, the ‘add_confirm_token’ function is called with a key generated by ‘Phauxth.Confirm.gen_token_link’:
changeset |> Phauxth.Confirm.DB_Utils.add_confirm_token(key)
Add a reset token to the user changeset.
Add the following two entries to your user schema:
field :reset_token, :string
field :reset_sent_at, Ecto.DateTime
As with ‘add_confirm_token’, the function ‘Phauxth.Confirm.gen_token_link’ can be used to generate the token and link.
Add the password hash for the new password to the database.
If the update is successful, the reset_token and reset_sent_at values will be set to nil.
Options
Three options are available:
password_strength_func - a function to check the strength of the password
- the default function checks that the password is at least 8 characters long
hash_name - name for the password hash (to be used when calling the database)
- the default is password_hash
hash_func - the hash function to be used
- the default function is Comeonin.Bcrypt.hashpwsalt
Examples
To change the password strength function:
Phauxth.Confirm.DB_Utils.password_reset(user, password, &strong_password/1)
To use a different hash function:
Phauxth.Confirm.DB_Utils.password_reset(user, password, &Argon2.hash_pwd_salt/1)