logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

pbkdf2_test.exs (1267B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Password.Pbkdf2Test do
  5. use Pleroma.DataCase, async: true
  6. alias Pleroma.Password.Pbkdf2, as: Password
  7. test "it generates the same hash as pbkd2_elixir" do
  8. # hash = Pbkdf2.hash_pwd_salt("password")
  9. hash =
  10. "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g"
  11. # Use the same randomly generated salt
  12. salt = Password.decode64("QJpEYw8iBKcnY.4Rm0eCVw")
  13. assert hash == Password.hash_pwd_salt("password", salt: salt)
  14. end
  15. @tag skip: "Works when Pbkd2 is present. Source: trust me bro"
  16. test "Pbkdf2 can verify passwords generated with it" do
  17. # Commented to prevent warnings.
  18. # hash = Password.hash_pwd_salt("password")
  19. # assert Pbkdf2.verify_pass("password", hash)
  20. end
  21. test "it verifies pbkdf2_elixir hashes" do
  22. # hash = Pbkdf2.hash_pwd_salt("password")
  23. hash =
  24. "$pbkdf2-sha512$1$QJpEYw8iBKcnY.4Rm0eCVw$UBPeWQ91RxSv3snxsb/ZzMeG/2aa03c541bbo8vQudREGNta5t8jBQrd00fyJp8RjaqfvgdZxy2rhSwljyu21g"
  25. assert Password.verify_pass("password", hash)
  26. end
  27. end