@@ -12,12 +12,15 @@ defmodule Pow.Ecto.Schema.Changeset do
1212
1313 * `:password_min_length` - minimum password length, defaults to 8
1414 * `:password_max_length` - maximum password length, defaults to 4096
15- * `:password_hash_verify` - the password hash and verify functions to use,
16- defaults to:
15+ * `:password_hash_verify` - the password hash and verify anonymous
16+ functions or MFAs, defaults to:
1717
1818 {&Pow.Ecto.Schema.Password.pbkdf2_hash/1,
1919 &Pow.Ecto.Schema.Password.pbkdf2_verify/2}
20- * `:email_validator` - the email validation function, defaults to:
20+
21+ It may be anonymous functions of MFAs.
22+ * `:email_validator` - the email validation anonymous function or
23+ MFA, defaults to:
2124
2225
2326 &Pow.Ecto.Schema.Changeset.validate_email/1
@@ -169,7 +172,7 @@ defmodule Pow.Ecto.Schema.Changeset do
169172 validator = get_email_validator ( config )
170173
171174 Changeset . validate_change ( changeset , :email , { :email_format , validator } , fn :email , email ->
172- case validator . ( email ) do
175+ case apply_function_or_mfa ( validator , [ email ] ) do
173176 :ok -> [ ]
174177 :error -> [ email: { "has invalid format" , validation: :email_format } ]
175178 { :error , reason } -> [ email: { "has invalid format" , validation: :email_format , reason: reason } ]
@@ -215,16 +218,12 @@ defmodule Pow.Ecto.Schema.Changeset do
215218 """
216219 @ spec verify_password ( Ecto.Schema . t ( ) , binary ( ) , Config . t ( ) ) :: boolean ( )
217220 def verify_password ( % { password_hash: nil } , _password , config ) do
218- config
219- |> get_password_hash_function ( )
220- |> apply ( [ "" ] )
221+ apply_password_hash_function ( config , [ "" ] )
221222
222223 false
223224 end
224225 def verify_password ( % { password_hash: password_hash } , password , config ) do
225- config
226- |> get_password_verify_function ( )
227- |> apply ( [ password , password_hash ] )
226+ apply_password_verify_function ( config , [ password , password_hash ] )
228227 end
229228
230229 defp maybe_require_password ( % { data: % { password_hash: nil } } = changeset ) do
@@ -259,21 +258,26 @@ defmodule Pow.Ecto.Schema.Changeset do
259258 defp maybe_validate_password_hash ( changeset ) , do: changeset
260259
261260 defp hash_password ( password , config ) do
262- config
263- |> get_password_hash_function ( )
264- |> apply ( [ password ] )
261+ apply_password_hash_function ( config , [ password ] )
265262 end
266263
267- defp get_password_hash_function ( config ) do
264+ defp apply_password_hash_function ( config , args ) do
268265 { password_hash_function , _ } = get_password_hash_functions ( config )
269266
270- password_hash_function
267+ apply_function_or_mfa ( password_hash_function , args )
268+ end
269+
270+ defp apply_function_or_mfa ( fun_or_mfa , apply_args ) do
271+ case fun_or_mfa do
272+ fun when is_function ( fun ) -> apply ( fun , apply_args )
273+ { mod , fun , args } when is_list ( args ) -> apply ( mod , fun , args ++ apply_args )
274+ end
271275 end
272276
273- defp get_password_verify_function ( config ) do
277+ defp apply_password_verify_function ( config , args ) do
274278 { _ , password_verify_function } = get_password_hash_functions ( config )
275279
276- password_verify_function
280+ apply_function_or_mfa ( password_verify_function , args )
277281 end
278282
279283 defp get_password_hash_functions ( config ) do
0 commit comments