X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/15d29c646b545b65bbedeed1f49329b9292671ba..1d1f194d598e54a5d6fb4f38fb569d4138af0dc8:/lib/password_hash.rb?ds=inline diff --git a/lib/password_hash.rb b/lib/password_hash.rb index 1bd80291a..5adfc7a34 100644 --- a/lib/password_hash.rb +++ b/lib/password_hash.rb @@ -29,6 +29,22 @@ module PasswordHash return hash == candidate end + def self.upgrade?(hash, salt) + if salt.nil? + return true + elsif salt =~ /!/ + algorithm, iterations, salt = salt.split("!") + return true if Base64.strict_decode64(salt).length != SALT_BYTE_SIZE + return true if Base64.strict_decode64(hash).length != HASH_BYTE_SIZE + return true if iterations.to_i != PBKDF2_ITERATIONS + return true if algorithm != DIGEST_ALGORITHM + else + return true + end + + return false + end + private def self.hash(password, salt, iterations, size, algorithm)