Module: Pwm
- Defined in:
- lib/pwm.rb,
lib/pwm/version.rb
Defined Under Namespace
Classes: TooShortException
Constant Summary collapse
- VERSION =
'1.2.2'
Class Method Summary collapse
-
.characters ⇒ Object
Internal: The set of characters from which passwords will be assembled.
-
.password(length = 16) ⇒ Object
Public: Generate a password.
Class Method Details
.characters ⇒ Object
Internal: The set of characters from which passwords will be assembled. This could be overridden if you don’t like the default.
Returns the set of characters as an Array.
12 13 14 |
# File 'lib/pwm.rb', line 12 def self.characters (('A'..'Z').to_a + ('a'..'z').to_a + ('2'..'9').to_a) - %w(I O l) end |
.password(length = 16) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pwm.rb', line 30 def self.password(length = 16) fail Pwm::TooShortException, "#{length} is too short." if length < 8 password = '' until acceptable?(password) password = (0..length - 1).reduce('') do |pw, n| pw + characters[rand(characters.length)] end end password end |