Skip to content

Instantly share code, notes, and snippets.

@tomasbasham
Last active February 26, 2021 11:28
Show Gist options
  • Save tomasbasham/6628f7a70bdb5a2ffc4e021bfb566778 to your computer and use it in GitHub Desktop.
Save tomasbasham/6628f7a70bdb5a2ffc4e021bfb566778 to your computer and use it in GitHub Desktop.

Revisions

  1. tomasbasham revised this gist Feb 26, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions pwned.rb
    Original file line number Diff line number Diff line change
    @@ -5,8 +5,8 @@
    hashed_password = Digest::SHA1.hexdigest password

    # SHA1 hashes will be 40 characters long
    prefix = hashed_password[0, 5].to_s.upcase
    suffix = hashed_password[5..-1].to_s.upcase
    prefix = hashed_password[0, 5].to_s.upcase # Get the first 5 characters
    suffix = hashed_password[5..-1].to_s.upcase # Get the remaining 35 characters

    puts "checking pwnedpasswords.com for: #{password}"
    uri = URI("https://api.pwnedpasswords.com/range/#{prefix}")
  2. tomasbasham revised this gist Feb 26, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pwned.rb
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    password = ARGV[0] || 'Password'
    hashed_password = Digest::SHA1.hexdigest password

    # SHA1 hases will be 40 characters long
    # SHA1 hashes will be 40 characters long
    prefix = hashed_password[0, 5].to_s.upcase
    suffix = hashed_password[5..-1].to_s.upcase

  3. tomasbasham created this gist Feb 26, 2021.
    17 changes: 17 additions & 0 deletions pwned.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    require 'digest'
    require 'net/http'

    password = ARGV[0] || 'Password'
    hashed_password = Digest::SHA1.hexdigest password

    # SHA1 hases will be 40 characters long
    prefix = hashed_password[0, 5].to_s.upcase
    suffix = hashed_password[5..-1].to_s.upcase

    puts "checking pwnedpasswords.com for: #{password}"
    uri = URI("https://api.pwnedpasswords.com/range/#{prefix}")
    res = Net::HTTP.get(uri)

    puts res.split("\n").find { |pwned_password|
    pwned_password.start_with? suffix
    }