X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fbotuser.rb;h=bed2b627cb59e9a36ea3a0ca1757f6771ecf88e8;hb=12906a51f698aebe1c9a5e19b15555ebbbcc4368;hp=7daaf66e9cf7d3baf3cb8d003618e67d71ccf6d1;hpb=98066bb754014b343dea272ebf6ec22babf9e8bf;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb index 7daaf66e..bed2b627 100644 --- a/lib/rbot/botuser.rb +++ b/lib/rbot/botuser.rb @@ -34,8 +34,8 @@ module Irc # def Auth.random_password(l=8) pwd = "" - 8.times do - pwd += (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr + l.times do + pwd << (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr end return pwd end @@ -101,6 +101,16 @@ class String end +class Symbol + + # Returns an Irc::Auth::Comand from the receiver + def to_irc_auth_command + Irc::Auth::Command.new(self) + end + +end + + module Irc @@ -160,6 +170,12 @@ module Irc end + # This is the error that gets raised when an invalid password is met + # + class InvalidPassword < RuntimeError + end + + # This is the basic class for bot users: they have a username, a password, # a list of netmasks to match against, and a list of permissions. # @@ -247,18 +263,19 @@ module Irc # This method sets the password if the proposed new password # is valid def password=(pwd=nil) - if pwd + pass = pwd.to_s + if pass.empty? + reset_password + else begin - raise InvalidPassword, "#{pwd} contains invalid characters" if pwd !~ /^[A-Za-z0-9]+$/ - raise InvalidPassword, "#{pwd} too short" if pwd.length < 4 - @password = pwd + raise InvalidPassword, "#{pass} contains invalid characters" if pass !~ /^[\x21-\x7e]+$/ + raise InvalidPassword, "#{pass} too short" if pass.length < 4 + @password = pass rescue InvalidPassword => e raise e rescue => e - raise InvalidPassword, "Exception #{e.inspect} while checking #{pwd}" + raise InvalidPassword, "Exception #{e.inspect} while checking #{pass.inspect} (#{pwd.inspect})" end - else - reset_password end end @@ -589,7 +606,7 @@ module Irc k = n.to_sym raise "No such BotUser #{n}" unless include?(k) if @botusers.has_key?(ircuser) - return true if @botusers[ircuser].username = n + return true if @botusers[ircuser].username == n # TODO # @botusers[ircuser].logout(ircuser) end