Added support for authentication in --share mode (via auth.json)
diff --git a/.gitignore b/.gitignore
index ce656b047..30b6ca3b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,3 +45,4 @@ experiment.py
 /node_modules
 /package-lock.json
 /.coverage*
+/auth.json
diff --git a/auth-example.json b/auth-example.json
new file mode 100644
index 000000000..59e321d01
--- /dev/null
+++ b/auth-example.json
@@ -0,0 +1,6 @@
+[
+    {
+        "user": "sitting-duck-1",
+        "pass": "very-bad-publicly-known-password-change-it"
+    }
+]
diff --git a/fooocus_version.py b/fooocus_version.py
index ac9cb1768..0eab2d2d8 100644
--- a/fooocus_version.py
+++ b/fooocus_version.py
@@ -1 +1 @@
-version = '2.1.738'
+version = '2.1.739'
diff --git a/modules/auth.py b/modules/auth.py
new file mode 100644
index 000000000..e609806fb
--- /dev/null
+++ b/modules/auth.py
@@ -0,0 +1,40 @@
+import json
+import hashlib
+
+from os.path import exists
+
+
+def auth_list_to_dict(auth_list):
+    auth_dict = {}
+    for auth_data in auth_list:
+        if 'user' in auth_data:
+            if 'hash' in auth_data:
+                auth_dict |= {auth_data['user']: auth_data['hash']}
+            elif 'pass' in auth_data:
+                auth_dict |= {auth_data['user']: hashlib.sha256(bytes(auth_data['pass'], encoding='utf-8')).hexdigest()}
+    return auth_dict
+
+
+def load_auth_data(filename=None):
+    auth_dict = None
+    if filename != None and exists(filename):
+        with open(filename, encoding='utf-8') as auth_file:
+            try:
+                auth_obj = json.load(auth_file)
+                if isinstance(auth_obj, list) and len(auth_obj) > 0:
+                    auth_dict = auth_list_to_dict(auth_obj)
+            except Exception as e:
+                print('load_auth_data, e: ' + str(e))
+    return auth_dict
+
+
+auth_dict = load_auth_data('auth.json')
+
+auth_enabled = auth_dict != None
+
+
+def check_auth(user, password):
+    if user not in auth_dict:
+        return False
+    else:   
+        return hashlib.sha256(bytes(password, encoding='utf-8')).hexdigest() == auth_dict[user]
diff --git a/update_log.md b/update_log.md
index 0f89296f2..a90e927a9 100644
--- a/update_log.md
+++ b/update_log.md
@@ -1,3 +1,7 @@
+# 2.1.739
+
+* Added support for authentication in --share mode (via auth.json).
+
 # 2.1.737
 
 * Allowed customizing resolutions in config. 
diff --git a/webui.py b/webui.py
index 7bd082f6e..01bfa04ce 100644
--- a/webui.py
+++ b/webui.py
@@ -18,6 +18,7 @@
 from modules.sdxl_styles import legal_style_names
 from modules.private_logger import get_current_html_path
 from modules.ui_gradio_extensions import reload_javascript
+from modules.auth import auth_enabled, check_auth
 
 
 def generate_clicked(*args):
@@ -376,5 +377,6 @@ def dump_default_english_config():
     inbrowser=args_manager.args.auto_launch,
     server_name=args_manager.args.listen,
     server_port=args_manager.args.port,
-    share=args_manager.args.share
+    share=args_manager.args.share,
+    auth=check_auth if args_manager.args.share and auth_enabled else None
 )
