Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add guide for switching between password hashing methods #590

Open
dcrck opened this issue Jan 12, 2021 · 1 comment
Open

add guide for switching between password hashing methods #590

dcrck opened this issue Jan 12, 2021 · 1 comment

Comments

@dcrck
Copy link

dcrck commented Jan 12, 2021

Pow has a guide for configuring the password hashing algorithm. There may come a time where people need to switch between password hashing methods (say, bcrypt/pbkdf2 to argon, or Pow's pbkdf2 implementation to pbkdf2_elixir). A guide or snippet on implementing this switch might be helpful.

@danschultzer
Copy link
Collaborator

Great idea. It's actually pretty straight forward. You just need a module that accepted deprecated hashing methods in verify function for :password_hash_methods. It could look like this to convert Pow's pbkdf2 impl to Argon2:

defmodule MyApp.Password do
  def hash(secret), do: Argon2.hash_pwd_salt(secret)

  def verify(secret, "$pbkdf2-" <> _ = hash), do: Pow.Ecto.Schema.Password.pbkdf2_verify(secret, hash)
  def verify(secret, "$argon2-" <> _ = hash), do: Argon2. verify_pass(secret, hash)
end

There are other details that should be included in the guide, like automatically hash with the new algo when the user signs if the current has in the db is with the old algo. The above also only works if the algo has been encoded in the hash. If not, then you would probably add a new column to the user that specify what algo or password version is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants