class HTAuth::DigestEntry
Object version of a single record from an htdigest file
Public
↑ topPublic Instance Methods
Check if the given password is the password of this entry.
# File lib/htauth/digest_entry.rb, line 79 def authenticated?(check_password) check = calc_digest(check_password) return Algorithm.secure_compare(check, digest) end
Internal
↑ topAttributes
The passwod digest of this entry
The realm of this entry
The user of this entry
Public Class Methods
Create an instance of this class from a line of text
- line
-
a line of text from a htdigest file
Returns¶ ↑
Returns an instance of DigestEntry
# File lib/htauth/digest_entry.rb, line 22 def from_line(line) parts = is_entry!(line) d = DigestEntry.new(parts[0], parts[1]) d.digest = parts[2] return d end
test if the given line is valid for this Entry
class
A valid entry must be composed of 3 parts, username:realm:md5sum where username, and realm do not contain the ':' character; and md5sum must be 32 characters long
- line
-
a line of text from a file
Returns¶ ↑
Returns the individual parts of the line
Raises InvalidDigestEntry
if it is not a a valid entry
# File lib/htauth/digest_entry.rb, line 39 def is_entry!(line) raise InvalidDigestEntry, "line commented out" if line =~ /\A#/ parts = line.strip.split(":") raise InvalidDigestEntry, "line must be of the format username:realm:md5checksum" if parts.size != 3 raise InvalidDigestEntry, "md5 checksum is not 32 characters long" if parts.last.size != 32 raise InvalidDigestEntry, "md5 checksum has invalid characters" if parts.last !~ /\A[[:xdigit:]]{32}\Z/ return parts end
Create a new Entry
with the given user, realm and password
# File lib/htauth/digest_entry.rb, line 62 def initialize(user, realm, password = "") @user = user @realm = realm @digest = calc_digest(password) end
Public Instance Methods
calculate the new digest of the given password
# File lib/htauth/digest_entry.rb, line 74 def calc_digest(password) ::Digest::MD5.hexdigest("#{user}:#{realm}:#{password}") end
Update the password of the entry with its new value
# File lib/htauth/digest_entry.rb, line 69 def password=(new_password) @digest = calc_digest(new_password) end