mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-01 05:39:09 +08:00
This was introduced to the standard library in Ruby 2.4. In my testing, it produces the same result, and is around 8x faster than our pure-ruby implementation
13 lines
300 B
Ruby
13 lines
300 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Pbkdf2
|
|
def self.hash_password(password, salt, iterations, algorithm = "sha256", length: 32)
|
|
OpenSSL::KDF.pbkdf2_hmac(
|
|
password,
|
|
salt: salt,
|
|
iterations: iterations,
|
|
length: length,
|
|
hash: algorithm,
|
|
).unpack1("H*")
|
|
end
|
|
end
|