Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (45 sloc) 1.393 kb
df02500 @richo initial import
richo authored
1 import hashlib
2 import pickle
3 import atexit
4 import logging
5 from lib import *
6
7 AUTH_FILE_NAME="authen.db"
8
9 class Authenticator(object):
10 """\
11 An object that statefully keeps track of all authentication
12 It is managed by AuthModule which tracks the server messages
13 """
14 def __init__(self, auth_hash='', valid_host=''):
15 self.auth_hash = auth_hash
16 self.valid_host = valid_host
17 self.authenticated = LowerList()
18 self.load()
19 atexit.register(self.save)
20
21 def try_auth(self, msg, password):
22 if msg.nick in self.authenticated:
23 return True
24 # Max kludge per user password
25 if hashlib.md5(password).hexdigest() == self.auth_hash:
26 self.authenticated.append(msg.nick)
27 return True
28 return False
29
30 def revoke_auth(self, nick):
31 count = 0
32 try:
33 while True:
34 self.authenticated.remove(nick)
35 count+=1
36 except ValueError:
37 return count > 0
38
39 def authed(self, msg):
40 return msg.nick in self.authenticated
41
42 def save(self):
43 pickle.dump(self.auth_data, open(AUTH_FILE_NAME, 'w'))
44 def load(self):
45 try:
46 fh = open(AUTH_FILE_NAME, 'r')
47 self.auth_data = pickle.load(fh)
48 except IOError:
49 self.auth_data = {}
50
51 # TODO
52 # Authentication decorator
53
Something went wrong with that request. Please try again.