Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/postdb/helpers/string.rb

Instance Method Summary collapse

Instance Method Details

#is_crypt?(crypt) ⇒ Boolean

Check if the string is a crypt

Arguments:

crypt: (Symbol)

Example:

>> crypt = "$6$AzeWWlznoLKPRJ1m$MeWkZqWKJp1XD.Jnt66D.Riubq7HT9vrRV0AwFXov2rxyzONR50ULiUFj7Kl6ykmh4EXsmpox8QUr6EUIo3NB0"
>> crypt.is_crypt?(:sha512)
=> true

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
# File 'lib/postdb/helpers/string.rb', line 12

def is_crypt?(crypt)
  case crypt
  when :sha512
    return false unless self =~ /^(\$6\$[a-zA-Z0-9]{16}\$[a-zA-Z0-9\.\/\\]{86})$/

    true
  else
    false
  end
end