Skip to content

Commit

Permalink
Detect hash algorithm automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
th3-z committed Mar 11, 2018
1 parent 16da3f6 commit 9194555
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion magicked_admin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run(self):
multiadmin_enabled = str_to_bool(config[server_name]["multiadmin_enabled"])

server = Server(server_name, address, user, password,
game_password, hashed=multiadmin_enabled)
game_password)
self.servers.append(server)

if map_autochange:
Expand Down
19 changes: 11 additions & 8 deletions magicked_admin/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@

class Server():

def __init__(self, name, address, username, password, game_password, hashed=False):
def __init__(self, name, address, username, password, game_password):
self.name = name
self.address = address
self.username = username
self.password = password
self.password_hash = "$sha1$" + \
sha1(password.encode("iso-8859-1", "ignore") + \
username.encode("iso-8859-1", "ignore")) \
.hexdigest()

self.game_password = game_password
if hashed:
self.password_hash = "$sha1$" + \
sha1(password.encode("iso-8859-1","ignore") + \
username.encode("iso-8859-1","ignore")) \
.hexdigest()
else:
self.password_hash = password

self.database = ServerDatabase(name)
self.session = self.new_session()
Expand Down Expand Up @@ -71,6 +70,10 @@ def new_session(self):
s = requests.Session()

login_page_response = s.get(login_url)

if "hashAlg = \"sha1\"" not in login_page_response.text:
login_payload['password_hash'] = self.password

login_page_tree = html.fromstring(login_page_response.content)

token = login_page_tree.xpath('//input[@name="token"]/@value')[0]
Expand Down

0 comments on commit 9194555

Please sign in to comment.