1 # Eloipool - Python Bitcoin pool server
2 # Copyright (C) 2011-2013 Luke Dashjr <luke-jr+eloipool@utopios.org>
3 # Written by Peter Leurs <kinlo@triplemining.com>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 from time import sleep
25 _logger = logging.getLogger('authentication.simplefile')
27 class simplefile(threading.Thread):
28 def __init__(self, filename, **ka):
29 super().__init__(**ka.get('thropts', {}))
32 self.lastmodified = os.path.getmtime(self.fn)
40 if self.lastmodified!=os.path.getmtime(self.fn):
41 self.lastmodified = os.path.getmtime(self.fn)
45 _logger.critical(traceback.format_exc())
50 fh = open(self.fn, "rb")
52 for line in data.split(b'\n'):
53 (user, passwd) = line.split(b'\t')
54 newdb[user.decode('utf8')]=passwd.decode('utf8')
56 _logger.info("Reloaded user db")
58 _logger.critical("fatal error reading userdatabase: %s", traceback.format_exc())
60 def checkAuthentication(self, user, password):
61 if user not in self.userdb:
63 if self.userdb[user] == password: