From 521a27c09de4c7360e2e42a30629feb99becf86e Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Wed, 17 Feb 2016 04:48:01 -0800 Subject: [PATCH] Using longer and mixed case passwords --- .../kde/kdeconnect/Helpers/RandomHelper.java | 24 +++++++++++++++++++ .../Plugins/SftpPlugin/SftpImpl.java | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/org/kde/kdeconnect/Helpers/RandomHelper.java diff --git a/src/org/kde/kdeconnect/Helpers/RandomHelper.java b/src/org/kde/kdeconnect/Helpers/RandomHelper.java new file mode 100644 index 00000000..93e7ac10 --- /dev/null +++ b/src/org/kde/kdeconnect/Helpers/RandomHelper.java @@ -0,0 +1,24 @@ +package org.kde.kdeconnect.Helpers; + + +import android.util.Log; + +import java.security.SecureRandom; + +public class RandomHelper { + public static SecureRandom secureRandom = new SecureRandom(); + + private static final char[] symbols = ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"+ + "abcdefghijklmnopqrstuvwxyz"+ + "1234567890").toCharArray(); + + + public static String randomString(int length) { + char[] buffer= new char[length]; + for (int idx = 0; idx < length; ++idx) { + buffer[idx] = symbols[secureRandom.nextInt(symbols.length)]; + } + return new String(buffer); + } + +} diff --git a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpImpl.java b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpImpl.java index 2433e05e..a68ad17f 100644 --- a/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpImpl.java +++ b/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpImpl.java @@ -39,6 +39,7 @@ import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; import org.apache.sshd.server.session.ServerSession; import org.apache.sshd.server.sftp.SftpSubsystem; import org.kde.kdeconnect.Device; +import org.kde.kdeconnect.Helpers.RandomHelper; import java.io.File; import java.net.Inet4Address; @@ -123,7 +124,8 @@ class SimpleSftpServer { public boolean start() { if (!started) { - String password = Long.toHexString(Double.doubleToLongBits(Math.random())); + + String password = RandomHelper.randomString(28); passwordAuth.setPassword(password); port = STARTPORT;