2 # httpauth/htpasswd -- Apache compatible htpasswd file
4 # Author: IPR -- Internet Programming with Ruby -- writers
5 # Copyright (c) 2003 Internet Programming with Ruby writers. All rights
8 # $IPR: htpasswd.rb,v 1.4 2003/07/22 19:20:45 gotoyuzo Exp $
10 require 'webrick/httpauth/userdb'
11 require 'webrick/httpauth/basicauth'
23 @auth_type = BasicAuth
24 open(@path,"a").close unless File::exist?(@path)
29 mtime = File::mtime(@path)
36 when %r!\A[^:]+:[a-zA-Z0-9./]{13}\z!
37 user, pass = line.split(":")
38 when /:\$/, /:\{SHA\}/
39 raise NotImplementedError,
40 'MD5, SHA1 .htpasswd file not supported'
42 raise StandardError, 'bad .htpasswd file'
53 tmp = Tempfile.new("htpasswd", File::dirname(output))
55 each{|item| tmp.puts(item.join(":")) }
57 File::rename(tmp.path, output)
63 def get_passwd(realm, user, reload_db)
68 def set_passwd(realm, user, pass)
69 @passwd[user] = make_passwd(realm, user, pass)
72 def delete_passwd(realm, user)
77 @passwd.keys.sort.each{|user|
78 yield([user, @passwd[user]])