#\r
def Auth.random_password(l=8)\r
pwd = ""\r
- 8.times do\r
- pwd += (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr\r
+ l.times do\r
+ pwd << (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr\r
end\r
return pwd\r
end\r
end\r
\r
\r
+class Symbol\r
+\r
+ # Returns an Irc::Auth::Comand from the receiver\r
+ def to_irc_auth_command\r
+ Irc::Auth::Command.new(self)\r
+ end\r
+\r
+end\r
+\r
+\r
module Irc\r
\r
\r
end\r
\r
\r
+ # This is the error that gets raised when an invalid password is met\r
+ #\r
+ class InvalidPassword < RuntimeError\r
+ end\r
+\r
+\r
# This is the basic class for bot users: they have a username, a password,\r
# a list of netmasks to match against, and a list of permissions.\r
#\r
# This method sets the password if the proposed new password\r
# is valid\r
def password=(pwd=nil)\r
- if pwd\r
+ pass = pwd.to_s\r
+ if pass.empty?\r
+ reset_password\r
+ else\r
begin\r
- raise InvalidPassword, "#{pwd} contains invalid characters" if pwd !~ /^[A-Za-z0-9]+$/\r
- raise InvalidPassword, "#{pwd} too short" if pwd.length < 4\r
- @password = pwd\r
+ raise InvalidPassword, "#{pass} contains invalid characters" if pass !~ /^[\x21-\x7e]+$/\r
+ raise InvalidPassword, "#{pass} too short" if pass.length < 4\r
+ @password = pass\r
rescue InvalidPassword => e\r
raise e\r
rescue => e\r
- raise InvalidPassword, "Exception #{e.inspect} while checking #{pwd}"\r
+ raise InvalidPassword, "Exception #{e.inspect} while checking #{pass.inspect} (#{pwd.inspect})"\r
end\r
- else\r
- reset_password\r
end\r
end\r
\r
k = n.to_sym\r
raise "No such BotUser #{n}" unless include?(k)\r
if @botusers.has_key?(ircuser)\r
- return true if @botusers[ircuser].username = n\r
+ return true if @botusers[ircuser].username == n\r
# TODO\r
# @botusers[ircuser].logout(ircuser)\r
end\r