1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 22:35:04 -05:00

* login and store only the MD5 password

This commit is contained in:
Reinhard Pointner 2015-05-08 08:59:15 +00:00
parent 955547dcd8
commit 4ab1b1afc5
2 changed files with 14 additions and 12 deletions

View File

@ -4,9 +4,11 @@ import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.FileUtilities.*;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -261,17 +263,20 @@ public final class WebServices {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public static final String LOGIN_SEPARATOR = ":";
public static final String LOGIN_OPENSUBTITLES = "osdb.user";
/** /**
* Initialize client settings from system properties * Initialize client settings from system properties
*/ */
static { static {
String[] osdbLogin = getLogin("osdb.user"); String[] osdbLogin = getLogin(LOGIN_OPENSUBTITLES);
OpenSubtitles.setUser(osdbLogin[0], osdbLogin[1]); OpenSubtitles.setUser(osdbLogin[0], osdbLogin[1]);
} }
public static String[] getLogin(String key) { public static String[] getLogin(String key) {
try { try {
String[] values = Settings.forPackage(WebServices.class).get(key, ":").split(":", 2); // empty username/password by default String[] values = Settings.forPackage(WebServices.class).get(key, LOGIN_SEPARATOR).split(LOGIN_SEPARATOR, 2); // empty username/password by default
if (values != null && values.length == 2 && values[0] != null && values[1] != null) { if (values != null && values.length == 2 && values[0] != null && values[1] != null) {
return values; return values;
} }
@ -282,16 +287,14 @@ public final class WebServices {
} }
public static void setLogin(String id, String user, String password) { public static void setLogin(String id, String user, String password) {
if (user == null || password == null || user.contains(":") || (user.isEmpty() && !password.isEmpty()) || (!user.isEmpty() && password.isEmpty())) { if (user == null || password == null || user.contains(LOGIN_SEPARATOR) || (user.isEmpty() && !password.isEmpty()) || (!user.isEmpty() && password.isEmpty())) {
throw new IllegalArgumentException(String.format("Illegal login: %s:%s", user, password)); throw new IllegalArgumentException(String.format("Illegal login: %s:%s", user, password));
} }
Settings settings = Settings.forPackage(WebServices.class); if (LOGIN_OPENSUBTITLES.equals(id)) {
String value = user.isEmpty() && password.isEmpty() ? null : user + ":" + password; String password_md5 = md5(StandardCharsets.UTF_8.encode(password));
OpenSubtitles.setUser(user, password_md5);
if (id.equals("osdb.user")) { Settings.forPackage(WebServices.class).put(id, String.join(LOGIN_SEPARATOR, user, password_md5));
settings.put(id, value);
OpenSubtitles.setUser(user, password);
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }

View File

@ -9,7 +9,6 @@ import static net.filebot.web.OpenSubtitlesHasher.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -57,12 +56,12 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
this.xmlrpc = new OpenSubtitlesXmlRpcWithRetryAndFloodLimit(String.format("%s v%s", name, version), 2, 3000); this.xmlrpc = new OpenSubtitlesXmlRpcWithRetryAndFloodLimit(String.format("%s v%s", name, version), 2, 3000);
} }
public synchronized void setUser(String username, String password) { public synchronized void setUser(String username, String password_md5) {
// cancel previous session // cancel previous session
this.logout(); this.logout();
this.username = username; this.username = username;
this.password = md5(StandardCharsets.UTF_8.encode(password)); this.password = password_md5;
} }
public boolean isAnonymous() { public boolean isAnonymous() {