Sha256: 60a6e59d5432f17dff0bd8e1993f930d6ece074684946f3a60ea3bedc834ce24

Contents?: true

Size: 695 Bytes

Versions: 5

Compression:

Stored size: 695 Bytes

Contents

module Ixtlan
  class Passwords
    def self.generate(length=64)
      if length > 0
        # A-Z starting with 97 and having 26 characters
        # a-z starting with 65 and having 26 characters
        # 0-9 starting with 48 and lies inside range starting with 33 and having 26 characters
        offset=[97, 65, 33]

        # collect random characters from the either of the above ranges
        begin
          pwd = (0..(length - 1)).collect do
            j = ActiveSupport::SecureRandom.random_number(78)
            (offset[j / 26] + (j % 26)).chr
          end.join
        end while !((pwd =~ /[a-z]/) && (pwd =~ /[A-Z]/) && (pwd =~ /[!-;]/))
        pwd
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ixtlan-0.4.0.pre4 lib/ixtlan/passwords.rb
ixtlan-0.4.0.pre3 lib/ixtlan/passwords.rb
ixtlan-0.4.0.pre2 lib/ixtlan/passwords.rb
ixtlan-0.4.0.pre lib/ixtlan/passwords.rb
ixtlan-0.3.0 lib/ixtlan/passwords.rb