Class | HTAuth::PasswdEntry |
In: |
lib/htauth/passwd_entry.rb
lib/htauth/passwd_entry.rb |
Parent: | Entry |
A single record in an htdigest file.
algorithm | [R] | |
algorithm | [R] | |
digest | [RW] | |
digest | [RW] | |
user | [RW] | |
user | [RW] |
# File lib/htauth/passwd_entry.rb, line 15 15: def from_line(line) 16: parts = is_entry!(line) 17: d = PasswdEntry.new(parts[0]) 18: d.digest = parts[1] 19: d.algorithm = Algorithm.algorithms_from_field(parts[1]) 20: return d 21: end
# File lib/htauth/passwd_entry.rb, line 15 15: def from_line(line) 16: parts = is_entry!(line) 17: d = PasswdEntry.new(parts[0]) 18: d.digest = parts[1] 19: d.algorithm = Algorithm.algorithms_from_field(parts[1]) 20: return d 21: end
test if a line is an entry, raise InvalidPasswdEntry if it is not. an entry must be composed of 2 parts, username:encrypted_password where username, and password do not contain the ’:’ character
# File lib/htauth/passwd_entry.rb, line 26 26: def is_entry!(line) 27: raise InvalidPasswdEntry, "line commented out" if line =~ /\A#/ 28: parts = line.strip.split(":") 29: raise InvalidPasswdEntry, "line must be of the format username:pssword" if parts.size != 2 30: return parts 31: end
test if a line is an entry, raise InvalidPasswdEntry if it is not. an entry must be composed of 2 parts, username:encrypted_password where username, and password do not contain the ’:’ character
# File lib/htauth/passwd_entry.rb, line 26 26: def is_entry!(line) 27: raise InvalidPasswdEntry, "line commented out" if line =~ /\A#/ 28: parts = line.strip.split(":") 29: raise InvalidPasswdEntry, "line must be of the format username:pssword" if parts.size != 2 30: return parts 31: end
test if a line is an entry and return true or false
# File lib/htauth/passwd_entry.rb, line 34 34: def is_entry?(line) 35: begin 36: is_entry!(line) 37: return true 38: rescue InvalidPasswdEntry 39: return false 40: end 41: end
test if a line is an entry and return true or false
# File lib/htauth/passwd_entry.rb, line 34 34: def is_entry?(line) 35: begin 36: is_entry!(line) 37: return true 38: rescue InvalidPasswdEntry 39: return false 40: end 41: end
# File lib/htauth/passwd_entry.rb, line 44 44: def initialize(user, password = "", alg = Algorithm::DEFAULT, alg_params = {} ) 45: @user = user 46: alg = Algorithm::DEFAULT if alg == Algorithm::EXISTING 47: @algorithm = Algorithm.algorithm_from_name(alg, alg_params) 48: @digest = algorithm.encode(password) 49: end
# File lib/htauth/passwd_entry.rb, line 44 44: def initialize(user, password = "", alg = Algorithm::DEFAULT, alg_params = {} ) 45: @user = user 46: alg = Algorithm::DEFAULT if alg == Algorithm::EXISTING 47: @algorithm = Algorithm.algorithm_from_name(alg, alg_params) 48: @digest = algorithm.encode(password) 49: end
# File lib/htauth/passwd_entry.rb, line 51 51: def algorithm=(alg) 52: if alg.kind_of?(Array) then 53: if alg.size == 1 then 54: @algorithm = alg.first 55: else 56: @algorithm = alg 57: end 58: else 59: @algorithm = Algorithm.algorithm_from_name(alg) unless Algorithm::EXISTING == alg 60: end 61: return @algorithm 62: end
# File lib/htauth/passwd_entry.rb, line 51 51: def algorithm=(alg) 52: if alg.kind_of?(Array) then 53: if alg.size == 1 then 54: @algorithm = alg.first 55: else 56: @algorithm = alg 57: end 58: else 59: @algorithm = Algorithm.algorithm_from_name(alg) unless Algorithm::EXISTING == alg 60: end 61: return @algorithm 62: end
check the password and make sure it works, in the case that the algorithm is unknown it tries all of the ones that it thinks it could be, and marks the algorithm if it matches
# File lib/htauth/passwd_entry.rb, line 73 73: def authenticated?(check_password) 74: authed = false 75: if algorithm.kind_of?(Array) then 76: algorithm.each do |alg| 77: if alg.encode(check_password) == digest then 78: @algorithm = alg 79: authed = true 80: break 81: end 82: end 83: else 84: authed = digest == algorithm.encode(check_password) 85: end 86: return authed 87: end
check the password and make sure it works, in the case that the algorithm is unknown it tries all of the ones that it thinks it could be, and marks the algorithm if it matches
# File lib/htauth/passwd_entry.rb, line 73 73: def authenticated?(check_password) 74: authed = false 75: if algorithm.kind_of?(Array) then 76: algorithm.each do |alg| 77: if alg.encode(check_password) == digest then 78: @algorithm = alg 79: authed = true 80: break 81: end 82: end 83: else 84: authed = digest == algorithm.encode(check_password) 85: end 86: return authed 87: end
# File lib/htauth/passwd_entry.rb, line 64 64: def password=(new_password) 65: if algorithm.kind_of?(Array) then 66: @algorithm = Algorithm.algorithm_from_name("crypt") 67: end 68: @digest = algorithm.encode(new_password) 69: end
# File lib/htauth/passwd_entry.rb, line 64 64: def password=(new_password) 65: if algorithm.kind_of?(Array) then 66: @algorithm = Algorithm.algorithm_from_name("crypt") 67: end 68: @digest = algorithm.encode(new_password) 69: end