Sha256: 1f59062995eafc3ecc815915785c1afe009af83d7298d2c0b39142c44b9df059

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

Contents

module Authlogic
  # Handles generating random strings. If SecureRandom is installed it will default to this and use it instead. SecureRandom comes with ActiveSupport.
  # So if you are using this in a rails app you should have this library.
  module Random
    extend self

    SecureRandom = (defined?(::SecureRandom) && ::SecureRandom) || (defined?(::ActiveSupport::SecureRandom) && ::ActiveSupport::SecureRandom)

    if SecureRandom
      def hex_token
        SecureRandom.hex(64)
      end

      def friendly_token
        # use base64url as defined by RFC4648
        SecureRandom.base64(15).tr('+/=', '-_ ').strip.delete("\n")
      end
    else
      def hex_token
        Authlogic::CryptoProviders::Sha512.encrypt(Time.now.to_s + (1..10).collect{ rand.to_s }.join)
      end

      FRIENDLY_CHARS = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a

      def friendly_token
        newpass = ""
        1.upto(20) { |i| newpass << FRIENDLY_CHARS[rand(FRIENDLY_CHARS.size-1)] }
        newpass
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
refinerycms-0.9.6.34 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.33 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.32 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.31 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.30 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.29 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.28 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.27 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.26 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.25 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.24 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.23 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.22 vendor/plugins/authlogic/lib/authlogic/random.rb
refinerycms-0.9.6.21 vendor/plugins/authlogic/lib/authlogic/random.rb