Skip to content

Instantly share code, notes, and snippets.

@haf
Created August 24, 2013 13:04
Show Gist options
  • Save haf/6328013 to your computer and use it in GitHub Desktop.
Save haf/6328013 to your computer and use it in GitHub Desktop.
Answer a security question!
require 'openssl'
require 'base64'
unless ARGV[0] && ARGV[1]
$stderr.puts 'you need to provide the question as the first argument'
$stderr.puts 'you need to provide the password as the second argument'
$stderr.puts 'usage: ./md5question.rb <question> <password> [ base64 | hex ]'
exit -1
end
MODE = ARGV[2] || 'base64'
hasher = OpenSSL::Digest::MD5.new
# calculate security question: md5(concat(security q as string, password))
puts case MODE
when 'base64'
Base64.encode64(hasher.digest(ARGV[0] + ARGV[1]))
when 'hex'
hasher.hexdigest(ARGV[0] + ARGV[1])
end
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment