|
1
|
|
|
# |
|
2
|
|
|
# Copyright 2001 - 2018 Ludek Smid [http://www.ospace.net/] |
|
3
|
|
|
# |
|
4
|
|
|
# This file is part of Outer Space. |
|
5
|
|
|
# |
|
6
|
|
|
# Outer Space is free software; you can redistribute it and/or modify |
|
7
|
|
|
# it under the terms of the GNU General Public License as published by |
|
8
|
|
|
# the Free Software Foundation; either version 2 of the License, or |
|
9
|
|
|
# (at your option) any later version. |
|
10
|
|
|
# |
|
11
|
|
|
# Outer Space is distributed in the hope that it will be useful, |
|
12
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
# GNU General Public License for more details. |
|
15
|
|
|
# |
|
16
|
|
|
# You should have received a copy of the GNU General Public License |
|
17
|
|
|
# along with Outer Space; if not, write to the Free Software |
|
18
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
19
|
|
|
# |
|
20
|
|
|
|
|
21
|
|
|
import hashlib |
|
22
|
|
|
import random |
|
23
|
|
|
import time |
|
24
|
|
|
|
|
25
|
|
|
class Account(object): |
|
26
|
|
|
|
|
27
|
|
|
def __init__(self): |
|
28
|
|
|
# credentials |
|
29
|
|
|
self.login = None |
|
30
|
|
|
self.nick = None |
|
31
|
|
|
self.passwd = None |
|
32
|
|
|
self.email = None |
|
33
|
|
|
# account options |
|
34
|
|
|
self.lastLogin = 0 |
|
35
|
|
|
self.blockedUntil = -1 # -1 for not blocked, > 0 for blocked |
|
36
|
|
|
self.blocked = 0 # 1 for blocked account |
|
37
|
|
|
self.confToken = None # e-mail confirmation token, if None e-mail has been confirmed |
|
38
|
|
|
self.hostIDs = {} # hostids and times |
|
39
|
|
|
self.isAI = False |
|
40
|
|
|
self.passwdHash = "sha256" # None means 'plaintext', in that case passwdSalt not used |
|
41
|
|
|
self.passwdSalt = hashlib.sha1(str(random.randrange(0, 1e10))).hexdigest() |
|
42
|
|
|
|
|
43
|
|
|
def addHostID(self, hostID): |
|
44
|
|
|
if hostID: |
|
45
|
|
|
self.hostIDs[hostID] = time.time() |
|
46
|
|
|
|
|
47
|
|
|
def hashPassword(self, plainPassword): |
|
48
|
|
|
if self.passwdHash is None: |
|
49
|
|
|
return plainPassword |
|
50
|
|
|
elif self.passwdHash == "sha256": |
|
51
|
|
|
return hashlib.sha256(self.passwdSalt + plainPassword).hexdigest() |
|
52
|
|
|
|
|
53
|
|
|
class AIAccount(Account): |
|
54
|
|
|
|
|
55
|
|
|
def __init__(self): |
|
56
|
|
|
Account.__init__(self) |
|
57
|
|
|
self.passwd = hashlib.sha1(str(random.randrange(0, 1e10))).hexdigest() |
|
58
|
|
|
# AI needs plaintext password for now |
|
59
|
|
|
self.passwdHash = None |
|
60
|
|
|
self.passwdSalt = None |
|
61
|
|
|
|
|
62
|
|
|
self.isAI = True |
|
63
|
|
|
self.aiType = None |
|
64
|
|
|
self.galaxyNames = [] |
|
65
|
|
|
|