encode url bug check login fixed

This commit is contained in:
simon 2020-11-18 18:21:25 +02:00
parent 14b0ab427a
commit 5cef32531b

View file

@ -14,12 +14,10 @@ import org.openplacereviews.opendb.ops.OpOperation;
import org.openplacereviews.opendb.util.JsonFormatter; import org.openplacereviews.opendb.util.JsonFormatter;
import org.openplacereviews.opendb.util.exception.FailedVerificationException; import org.openplacereviews.opendb.util.exception.FailedVerificationException;
import java.io.BufferedReader; import java.io.*;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyPair; import java.security.KeyPair;
import java.security.Security; import java.security.Security;
import java.util.*; import java.util.*;
@ -38,16 +36,22 @@ public class OpenDBAPI {
* params * params
* - username: blockchain username in format "openplacereviews:test_1" * - username: blockchain username in format "openplacereviews:test_1"
* - privatekey: "base64:PKCS#8:actualKey" * - privatekey: "base64:PKCS#8:actualKey"
* * Need to encode key
* Do not call on mainThread * Do not call on mainThread
*/ */
public boolean checkPrivateKeyValid(String username, String privateKey){ public boolean checkPrivateKeyValid(String username, String privateKey) throws UnsupportedEncodingException {
String url = BuildConfig.OPR_BASE_URL + checkLoginEndpoint + String url = null;
"name=" + try {
username + url = BuildConfig.OPR_BASE_URL + checkLoginEndpoint +
"&" + "name=" +
"privateKey=" + username +
privateKey; "&" +
"privateKey=" +
//need to encode the key
URLEncoder.encode(privateKey, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw e;
}
StringBuilder response = new StringBuilder(); StringBuilder response = new StringBuilder();
return (NetworkUtils.sendGetRequest(url,null,response) == null) && return (NetworkUtils.sendGetRequest(url,null,response) == null) &&
response.toString().contains(LOGIN_SUCCESS_MESSAGE); response.toString().contains(LOGIN_SUCCESS_MESSAGE);