Sha256: 75030b94dfeaa3b45ea8252a5d96c992cffe58e912567ed6cc87bde4da1a8f13

Contents?: true

Size: 1.22 KB

Versions: 56

Compression:

Stored size: 1.22 KB

Contents

# encoding: UTF-8
#
# Copyright (c) 2010-2018 GoodData Corporation. All rights reserved.
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

require 'securerandom'

module GoodData
  module Helpers
    module CryptoHelper
      class << self
        def generate_password
          sprinkle(SecureRandom.base64(32))
        end

        private

        # Pseudo-randomly "sprinkles" the given string
        # with 4 character groups (digit, lower case,
        # upper case, symbols).
        # @param [String] password
        def sprinkle(password)
          password_dup = password.dup
          positions = 0..password.size
          password_dup.insert(rand(positions), digit)
          password_dup.insert(rand(positions), lower)
          password_dup.insert(rand(positions), upper)
          password_dup.insert(rand(positions), symbol)
          password_dup
        end

        def digit
          (0..9).to_a.sample.to_s
        end

        def lower
          ('a'..'z').to_a.sample
        end

        def upper
          ('A'..'Z').to_a.sample
        end

        def symbol
          '!@#$%&/()+?*'.chars.sample
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
gooddata-2.1.0-java lib/gooddata/helpers/crypto_helper.rb
gooddata-2.1.0 lib/gooddata/helpers/crypto_helper.rb
gooddata-2.0.1-java lib/gooddata/helpers/crypto_helper.rb
gooddata-2.0.1 lib/gooddata/helpers/crypto_helper.rb
gooddata-2.0.0-java lib/gooddata/helpers/crypto_helper.rb
gooddata-2.0.0 lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.6-java lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.6 lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.5-java lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.5 lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.4-java lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.4 lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.3-java lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.3 lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.2-java lib/gooddata/helpers/crypto_helper.rb
gooddata-1.3.2 lib/gooddata/helpers/crypto_helper.rb