Sha256: 32a15f25daad9173bfd96d0b9074cc087e54fe8b6765a91ff6826badcd9ca2a3
Contents?: true
Size: 996 Bytes
Versions: 1
Compression:
Stored size: 996 Bytes
Contents
require "pwm/version" module Pwm # 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. def self.characters (('A'..'Z').to_a + ('a'..'z').to_a + ('2'..'9').to_a) - ['I', 'O', 'l'] end # Public: Generate a password. # # length - The length of the password. Minimum is 8. Default is 16. # # Examples # # Pwm.password # # => 'SPdHeZnn9rut4AUz' # # Pwm.password(8) # # => 'oUX4fmqr' # # Returns the generated password as a String if length >= 8, # or nil is length < 8. def self.password(length = 16) if length < 8 nil else password = '' until (password.match(/[A-Z]/) && password.match(/[a-z]/) && password.match(/[0-9]/)) password = (0..length - 1).inject('') do |pw, n| pw + characters[rand(characters.length)] end end password end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pwm-1.1.1 | lib/pwm.rb |