From a7a65b89386c0bec5e0e76b274177ec05c490ad1 Mon Sep 17 00:00:00 2001
From: Sergei Kotlyachkov <kotl@google.com>
Date: Fri, 26 May 2017 22:58:22 -0400
Subject: [PATCH] Using same password dialog as in Arduino IDE to authenticate.
 Blank password will work for non-authenticated case.

---
 src/ESP8266FS.java | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/ESP8266FS.java b/src/ESP8266FS.java
index fd210f2..d3054c1 100644
--- a/src/ESP8266FS.java
+++ b/src/ESP8266FS.java
@@ -34,12 +34,14 @@
 import java.lang.reflect.InvocationTargetException;
 import javax.swing.JOptionPane;
 
+
 import processing.app.PreferencesData;
 import processing.app.Editor;
 import processing.app.Base;
 import processing.app.BaseNoGui;
 import processing.app.Platform;
 import processing.app.Sketch;
+import processing.app.forms.PasswordAuthorizationDialog;
 import processing.app.tools.Tool;
 import processing.app.helpers.ProcessUtils;
 import processing.app.debug.TargetPlatform;
@@ -307,7 +309,23 @@ private void createAndUpload(){
       
       System.out.println("[SPIFFS] IP     : "+serialPort);
       System.out.println();
-      sysExec(new String[]{pythonCmd, espota.getAbsolutePath(), "-i", serialPort, "-s", "-f", imagePath});
+
+      PasswordAuthorizationDialog dialog = new PasswordAuthorizationDialog(
+             editor, "Type board password to upload new data");
+      dialog.setLocationRelativeTo(editor);
+      dialog.setVisible(true);
+      if (dialog.isCancelled()) {
+        editor.statusNotice("Upload cancelled");
+        return;
+      }
+      String pass = dialog.getPassword();
+      if (pass.isEmpty()) {
+        sysExec(new String[]{pythonCmd, espota.getAbsolutePath(),
+            "-i", serialPort, "-s", "-f", imagePath});
+      } else {
+        sysExec(new String[]{pythonCmd, espota.getAbsolutePath(),
+                             "-i", serialPort, "-a", pass, "-s", "-f", imagePath});
+      }
     } else {
       System.out.println("[SPIFFS] address: "+uploadAddress);
       System.out.println("[SPIFFS] reset  : "+resetMethod);