Skip to content

Instantly share code, notes, and snippets.

@vitaliel
Created September 24, 2018 17:58
Show Gist options
  • Save vitaliel/863fe775f33ef50c3029b8af7d7916a6 to your computer and use it in GitHub Desktop.
Save vitaliel/863fe775f33ef50c3029b8af7d7916a6 to your computer and use it in GitHub Desktop.
# Ported code from https://stackoverflow.com/questions/46888656/how-to-check-password-in-node-js-from-aspnetusers-net-core
# ruby 2.5.1
require "base64"
require "openssl"
# Value from table AspNetUsers, PasswordHash field
h="AQAAAAEAACcQAAAAEFzA9xEehSfcI4qgvuIPlkAXTzLrPuvVtVDW3g4+QHTR4XoIzXUikDJITOi82f4qWQ=="
h_bytes = Base64.decode64(h)
salt = ''
sub_key = ''
1.upto(h_bytes.length - 1) do |i|
if (i > 12 && i <= 28)
salt << h_bytes[i]
end
if i > 28
sub_key << h_bytes[i]
end
end
# User passwd
pass = 'q123q123'
crypt = OpenSSL::KDF.pbkdf2_hmac(pass, salt: salt, iterations: 10000, length: 256, hash: OpenSSL::Digest::SHA256.new)
if crypt.index(sub_key) == 0
puts "Passwd patch"
else
puts "Passwd DO NOT match"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment