module UnixCrypt

Constants

Error
IDENTIFIER_MAPPINGS
SaltTooLongError
VERSION

Public Class Methods

valid?(password, string) click to toggle source
# File lib/unix_crypt.rb, line 10
def self.valid?(password, string)
  # Handle the original DES-based crypt(3)
  return password.crypt(string) == string if string.length == 13

  # All other types of password follow a standard format
  return false unless m = string.match(/\A\$([156])\$(?:rounds=(\d+)\$)?(.+)\$(.+)/)

  hash = IDENTIFIER_MAPPINGS[m[1]].hash(password, m[3], m[2] && m[2].to_i)
  hash == m[4]
end