main2
Bob Mottram 2019-10-25 13:52:07 +01:00
parent 0638290ae3
commit 1cafe0c8dd
1 changed files with 8 additions and 9 deletions

View File

@ -2834,15 +2834,14 @@ class PubServer(BaseHTTPRequestHandler):
print('Login success: '+loginNickname) print('Login success: '+loginNickname)
self.send_response(303) self.send_response(303)
# This produces a deterministic token based on nick+password+salt # This produces a deterministic token based on nick+password+salt
if not self.server.salts.get(loginNickname): saltFilename=self.server.baseDir+'/accounts/'+loginNickname+'@'+self.server.domain+'/.salt'
saltFilename=self.server.baseDir+'/accounts/'+loginNickname+'@'+self.server.domain+'/.salt' if os.path.isfile(saltFilename):
if os.path.isfile(saltFilename): with open(saltFilename, 'r') as fp:
with open(saltFilename, 'r') as fp: self.server.salts[loginNickname] = fp.read()
self.server.salts[loginNickname] = fp.read() else:
else: self.server.salts[loginNickname]=createPassword(32)
self.server.salts[loginNickname]=createPassword(32) with open(saltFilename, 'w') as fp:
with open(saltFilename, 'w') as fp: fp.write(self.server.salts[loginNickname])
fp.write(self.server.salts[loginNickname])
self.server.tokens[loginNickname]=sha256((loginNickname+loginPassword+self.server.salts[loginNickname]).encode('utf-8')).hexdigest() self.server.tokens[loginNickname]=sha256((loginNickname+loginPassword+self.server.salts[loginNickname]).encode('utf-8')).hexdigest()
self.server.tokensLookup[self.server.tokens[loginNickname]]=loginNickname self.server.tokensLookup[self.server.tokens[loginNickname]]=loginNickname
self.send_header('Set-Cookie', 'epicyon='+self.server.tokens[loginNickname]+'; SameSite=Strict') self.send_header('Set-Cookie', 'epicyon='+self.server.tokens[loginNickname]+'; SameSite=Strict')