Class: Dicemypass::CLI
- Inherits:
-
Thor
- Object
- Thor
- Dicemypass::CLI
- Defined in:
- lib/dicemypass/cli.rb
Instance Method Summary collapse
Instance Method Details
#about ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/dicemypass/cli.rb', line 70 def about puts Dicemypass::BANNER.bold.red puts 'version: '.bold + Dicemypass::VERSION.green puts 'author: '.bold + 'Keelana'.green puts 'homepage: '.bold + 'https://github.com/kchar92/dicemypass'.green puts 'learn more: '.bold + 'https://codingdose.info'.green puts # extra line, somehow I like them. end |
#check_pass ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dicemypass/cli.rb', line 57 def check_pass puts "Enter your password, press ENTER when you're done." password = ask('Password (hidden):'.yellow, echo: false) (puts "Aborted.".red.bold; exit) if password.empty? dataset_count = Dicemypass.check_pwned(password) vuln_msg = "Your password appears in #{dataset_count} datasets!".red.bold safe_msg = "Your password was not found in a dataset.".green.bold puts dataset_count ? vuln_msg : safe_msg end |
#gen_pass(pass_length = 7) ⇒ Object
18 19 20 21 22 23 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 54 |
# File 'lib/dicemypass/cli.rb', line 18 def gen_pass(pass_length = 7) # Force our length value to be an integer new_passphrase = Dicemypass.gen_passphrase(pass_length.to_i) # If our options :clipboard and :hibp are true, then proceeds # to copy the contents of the passphrase to the clipboard # and check if the passphrase is vulnerable. Clipboard.copy(new_passphrase.join(' ')) if [:clipboard] dataset_count = Dicemypass.check_pwned(new_passphrase) if [:hibp] # To add colors, first we store the available colors in a variable # but we eliminate the color black which makes some words to be # unreadable in the terminal. After that, we map the passphrase list # and assign a random color to each one of them. colors = String.colors colors.delete(:black) # black color looks ugly in the terminal new_passphrase.map! do |phrase| random_color = colors.sample phrase.colorize(random_color) end # We add default messages in case our options are activated. A green bold # message when the user wants to copy the passphrase, another one if the # passphrase is safe, and a red bold one if the passphrase is vulnerable. copy_msg = '- Copied to clipboard.'.bold.green vuln_pass_msg = "- WARNING: Passphrase appears in #{dataset_count} datasets!".red.bold safe_pass_msg = '- Password was not found in a dataset.'.green.bold # Bold the title passphrase and then join the passphrase to make it a string. puts '- Passphrase: '.bold + new_passphrase.join(' ') # If the clipboard option is active then display the clipboard message puts copy_msg if [:clipboard] # If the option :hibp is True then check if the pass is found in a dataset. # If dataset_cout is not nil then display vuln_pass_msg, else display # the safe_pass_msg. puts dataset_count ? vuln_pass_msg : safe_pass_msg if [:hibp] end |