Sha256: 44a4a3d5fea60c8972de7917f01677ac34d8d28e9e52c39eff2cf36ee7b5e437

Contents?: true

Size: 852 Bytes

Versions: 10

Compression:

Stored size: 852 Bytes

Contents

# TITLE:
#
#   Crypt
#
# SUMMARY:
#
#   Adds a default salt to crypt.
#
# TODO:
#
#   - Deprecate once/if part of Ruby proper.

#
class String

  alias_method :_crypt, :crypt

  # Common Unix cryptography method.
  #
  def crypt(salt=nil)
    salt ||= (
      (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr +
      (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr
    )
    _crypt(salt)
  end

  # Common Unix cryptography in-place method.
  #
  def crypt!(salt=nil)
    replace(crypt(salt))
  end

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TestStringCrypt < Test::Unit::TestCase

    def test_crypt
      assert_nothing_raised { "abc 123".crypt }
    end

    def test_crypt!
      assert_nothing_raised { "abc 123".crypt! }
    end

  end

=end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.0.0 lib/core/facets/string/crypt.rb
facets-2.0.1 lib/core/facets/string/crypt.rb
facets-2.0.2 lib/core/facets/string/crypt.rb
facets-2.0.5 lib/core/facets/string/crypt.rb
facets-2.1.0 lib/core/facets/string/crypt.rb
facets-2.1.2 lib/core/facets/string/crypt.rb
facets-2.1.1 lib/core/facets/string/crypt.rb
facets-2.0.3 lib/core/facets/string/crypt.rb
facets-2.0.4 lib/core/facets/string/crypt.rb
facets-2.1.3 lib/core/facets/string/crypt.rb