class AttrPassword::DES

The DES class

Public Instance Methods

crypt_password(password) click to toggle source

Crypt the password

Arguments:

password: (String)

Example:

>> backend.crypt_password("P@ssw0rd")
=> "5F9dBJsU0KiKQ"
# File lib/attr_password/des.rb, line 14
def crypt_password(password)
  # Get the DES crypt password
  UnixCrypt::DES.build(password)
end
validate_password(password, password_hash) click to toggle source

Check if a password is valid

Arguments:

password_hash: (String)
password: (String)

Example:

>> backend.crypt_password("P@ssw0rd", "5F9dBJsU0KiKQ")
=> true
# File lib/attr_password/des.rb, line 29
def validate_password(password, password_hash)
  # Ensure the password is set
  return false unless password

  # Ensure the password hash is set
  return false unless password_hash

  # Check if the password is valid
  UnixCrypt.valid?(password, password_hash)
end