Module: Dicemypass
- Defined in:
- lib/dicemypass.rb,
lib/dicemypass/cli.rb,
lib/dicemypass/version.rb
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- VERSION =
"0.2.1"
- BANNER =
''' ______ ___ _______ _______ __ __ __ __ _______ _______ _______ _______ | | | | | || || |_| || | | || || _ || || | | _ || | | || ___|| || |_| || _ || |_| || _____|| _____| | | | || | | || |___ | || || |_| || || |_____ | |_____ | |_| || | | _|| ___|| ||_ _|| ___|| ||_____ ||_____ | | || | | |_ | |___ | ||_|| | | | | | | _ | _____| | _____| | |______| |___| |_______||_______||_| |_| |___| |___| |__| |__||_______||_______| '''
Class Method Summary collapse
- .check_pwned(passphrase) ⇒ Object
-
.gen_passphrase(pass_length = 7) ⇒ Object
The default passphrase length should be 7.
Class Method Details
.check_pwned(passphrase) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dicemypass.rb', line 24 def self.check_pwned(passphrase) # If the passphrase is an array generated by gen_passphrase we convert # the passphrase to an unified string, if it's a string already then # no changes are applied to the passphrase variable. passphrase = passphrase.join(' ') if passphrase.is_a?(Array) # We encode our passphrase to SHA-1, and save or prefix consisting # in 5 characters to the variable sha1_excerpt and the suffix to # the variable sha1_to_look_for. sha1_pass = Digest::SHA1.hexdigest(passphrase) sha1_excerpt = sha1_pass[0...5] sha1_to_look_for = sha1_pass[5..-1] # We make the API call with our SHA-1 prefix and store the response to # the variable api_request api_url = URI("https://api.pwnedpasswords.com/range/#{sha1_excerpt}") api_request = Net::HTTP.get(api_url) # The response is text instead of JSON, needs to format the response # to a dictionary so the rest of the hash can be located easier. # => String '0018A45C4D1DEF81644B54AB7F969B88D65:21' # => Array ['0018A45C4D1DEF81644B54AB7F969B88D65:21', ...] # => 2D Array [['0018A45C4D1DEF81644B54AB7F969B88D65', '21'], ...] # => Hash {'0018A45C4D1DEF81644B54AB7F969B88D65': 21, ...} striped_list = api_request.split("\r\n") pass_list = striped_list.map { |hash| hash.split(':') } hash_list = Hash[*pass_list.flatten!] hash_list[sha1_to_look_for.upcase] end |
.gen_passphrase(pass_length = 7) ⇒ Object
The default passphrase length should be 7
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dicemypass.rb', line 11 def self.gen_passphrase(pass_length = 7) # Read filename eff_long_wordlist and save it as a list. wordlist = File.readlines(@eff_wordlist) # Strip the '\n' out of every line. wordlist.map(&:strip!) # Shuffle the list and return a list up to pass_length words # which in the case would be equal to 7 words. wordlist.shuffle[0...pass_length] end |