Passw is a Ruby gem for generating secure, customizable passwords programmatically or directly via the terminal. It offers advanced options for character type enforcement, exclusion lists, entropy-based strength assessment, and more.
Ruby 2.7 or higher is recommended.
gem install passwOr add it to your Gemfile:
gem 'passw'
To generate a password, simply require passw and use the generate method:
require 'passw'
# Generate a 12-character password
Passw.generate(12) # => e.g., ^IUH91234la*Passw supports the following options and combinations of them:
length:- Set the length of the password (default:12).lowercase:- Include lowercase letters (default:true).uppercase:- Include uppercase letters (default:true).symbols:- Include special characters (default:true).numbers:- Include numeric characters (default:true).duplicates:- Allow duplicate characters (default:true).enforce_types:- Ensure at least one of each selected character type (default:true).avoid_sequences:- Prevent sequential characters (e.g., abc, 123).exclude:- Exclude specific characters (e.g., O, 0, I, l).min_length:- Enforce a minimum password length (default: 8).entropy:- Calculate and display the password's entropy for strength assessment.
Passw.generate(12) # => e.g., |vwr8j5VV8WPassw.generate(12, {
lowercase: true, # Include lowercase letters
uppercase: true, # Include uppercase letters
symbols: true, # Include symbols
numbers: true, # Include numbers
duplicates: false, # No duplicate characters
enforce_types: true, # At least one of each type
avoid_sequences: true, # No sequential characters
exclude: ['O', '0', 'I', 'l'] # Exclude characters that may cause confusion
})
# => e.g., qU.b"fo+P>WlPassw includes a command-line executable for generating passwords directly from the terminal:
passw <password length>
For example:
passw 12The CLI supports additional options for fine-tuning the password. Here's the full list:
--lowercase: Include lowercase letters (default: enabled).--uppercase: Include uppercase letters (default: enabled).--symbols: Include symbols (default: enabled).--numbers: Include numbers (default: enabled).--no-duplicates: Disallow duplicate characters in the password.--enforce-types: Ensure at least one of each selected character type (default: enabled).--avoid-sequences: Avoid sequential characters (e.g.,abc,123).--excludeCHARS: Exclude specific characters, using a comma-separated list (e.g., O,0,I,l).--min-lengthLENGTH: Set a minimum password length (default: 8).
Generate a Password Without Symbols:
passw 12 --no-symbolsGenerate a Password Excluding Specific Characters
passw 12 --exclude O,0,I,lGenerate a Password With No Duplicate Characters and No Sequential Characters
passw 12 --no-duplicates --avoid-sequencesFor a full list of options, use:
passw --helpTo run the tests for passw, run:
rake test
# Running:
........
Finished in 0.000668s, 11976.0479 runs/s, 70359.2814 assertions/s.
8 runs, 47 assertions, 0 failures, 0 errors, 0 skipsThis project is licensed under the GPL-3.0-or-later license. See LICENSE for details.
