Added changeset encyption function for password field
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
				
			|||||||
defmodule Sukaato.CustomValidators do
 | 
					defmodule Sukaato.CustomValidators do
 | 
				
			||||||
  import Ecto.Changeset
 | 
					  import Ecto.Changeset
 | 
				
			||||||
  import Validate
 | 
					  import Validate
 | 
				
			||||||
 | 
					  import Argon2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @moduledoc """
 | 
					  @moduledoc """
 | 
				
			||||||
  Provide a collecton of custom validation functions for Ecto database
 | 
					  Provide a collecton of custom validation functions for Ecto database
 | 
				
			||||||
@@ -24,4 +25,12 @@ defmodule Sukaato.CustomValidators do
 | 
				
			|||||||
      add_error(changeset, field, "is not a valid map")
 | 
					      add_error(changeset, field, "is not a valid map")
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def encrypt_password(changeset, field \\ :password) when is_atom(field) do
 | 
				
			||||||
 | 
					    field_value = get_field(changeset, field)
 | 
				
			||||||
 | 
					    field_value = hash_pwd_salt(field_value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    put_change(changeset, field, field_value)
 | 
				
			||||||
 | 
					    changeset
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user