diff --git a/app.py b/app.py index ac19741ce..1dfb5aea3 100644 --- a/app.py +++ b/app.py @@ -10,6 +10,11 @@ import random import string import configparser import bcrypt +import requests +import json +import os +import binascii +import hashlib from flask import render_template, redirect @@ -303,5 +308,24 @@ def load_user(user_id): else: return None +syncServerUrl = config['Sync']['sync-server-url'] +syncServerUsername = config['Sync']['sync-server-username'] +syncServerPassword = config['Sync']['sync-server-password'] + +nonce = binascii.hexlify(bytearray(os.urandom(32))) + +print('Nonce: ' + nonce) + +# SHA256(user + ":" + SHA256(user + ":" + password) + ":" + nonce) where SHA256 is a hex encoded value +auth = hashlib.sha256(syncServerUsername + ":" + hashlib.sha256(syncServerPassword + ":" + syncServerPassword).hexdigest() + ":" + nonce).hexdigest() + +response = requests.post(syncServerUrl + "/login", json={ + 'user': syncServerUsername, + 'nonce': nonce, + 'auth': auth +}) + +print(response) + if __name__ == '__main__': - app.run(host='0.0.0.0') + app.run(host='0.0.0.0') \ No newline at end of file diff --git a/config.ini b/config.ini index 695f0a70b..cbda03fc7 100644 --- a/config.ini +++ b/config.ini @@ -2,4 +2,9 @@ # Enter below credentials with with which you want to authenticate to Notecase web app username=adam # This is bcrypt password hash. You can use generate-password.py (in this directory) to hash your password -password-hash=$2b$12$jcbhRx6WRbCRogpCckH1hehWrHWgFaFYC3u3ebdVURJX36..fdAca \ No newline at end of file +password-hash=$2b$12$jcbhRx6WRbCRogpCckH1hehWrHWgFaFYC3u3ebdVURJX36..fdAca + +[Sync] +sync-server-url=http://localhost:57201 +sync-server-username=syncuser +sync-server-password=password \ No newline at end of file