* login and store only the MD5 password

This commit is contained in:
Reinhard Pointner 2015-05-08 08:20:20 +00:00
parent 2fddcf0a2d
commit c7925f9b50
2 changed files with 19 additions and 17 deletions

View File

@ -12,6 +12,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.math.BigInteger;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -24,6 +25,8 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
@ -627,6 +630,20 @@ public final class FileUtilities {
return Pattern.compile("\\s*[\\\\/]+\\s*").matcher(path).replaceAll(replacement); return Pattern.compile("\\s*[\\\\/]+\\s*").matcher(path).replaceAll(replacement);
} }
public static String md5(byte[] data) {
return md5(ByteBuffer.wrap(data));
}
public static String md5(ByteBuffer data) {
try {
MessageDigest hash = MessageDigest.getInstance("MD5");
hash.update(data);
return String.format("%032x", new BigInteger(1, hash.digest())); // as hex string
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
public static List<File> asFileList(Object... paths) { public static List<File> asFileList(Object... paths) {
List<File> files = new ArrayList<File>(paths.length); List<File> files = new ArrayList<File>(paths.length);
for (Object it : paths) { for (Object it : paths) {

View File

@ -8,10 +8,8 @@ import static net.filebot.web.OpenSubtitlesHasher.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger;
import java.net.URI; import java.net.URI;
import java.security.MessageDigest; import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -64,7 +62,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
this.logout(); this.logout();
this.username = username; this.username = username;
this.password = password; this.password = md5(StandardCharsets.UTF_8.encode(password));
} }
public boolean isAnonymous() { public boolean isAnonymous() {
@ -348,19 +346,6 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
xmlrpc.uploadSubtitles(info, sub); xmlrpc.uploadSubtitles(info, sub);
} }
/**
* Calculate MD5 hash.
*/
private String md5(byte[] data) throws IOException {
try {
MessageDigest hash = MessageDigest.getInstance("MD5");
hash.update(data);
return String.format("%032x", new BigInteger(1, hash.digest())); // as hex string
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e); // won't happen
}
}
@Override @Override
public List<Movie> searchMovie(String query, Locale locale) throws Exception { public List<Movie> searchMovie(String query, Locale locale) throws Exception {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();