私はネイティブのAndroidアプリを開発しています。私は大文字と小文字を区別しないログインページを持っています。Android - アプリをログインさせる、大文字と小文字を区別する
例:パスワード管理者と管理者の両方がログインできるようになります。これは可能ではありません。
ログインが有効です。私の問題は大文字と小文字を区別しています。私はまだJavaとAndroidには新しく、大文字と小文字を区別するためのコードをどこに置くべきかは不明です。
equalsIgnoreCase()を使用する必要がありますか?
もしそうなら、このログインではどのようにequalsIgnoreCase()を使用しますか?あなたはRest APIを使用してユーザーログインを完了していますか?
どのようなヘルプも充当されます。
private class LoginProcess extends AsyncTask<Void, Void, String> {
protected void onPreExecute(){
super.onPreExecute();
dialog_login.show();
}
String user = userInput.getText().toString();
String pass = passInput.getText().toString();
@Override
protected String doInBackground(Void... voids) {
String address = my_url + "api/user/login.json";
HttpURLConnection urlConnection;
String requestBody;
Uri.Builder builder = new Uri.Builder();
Map<String, String> params = new HashMap<>();
params.put("username", user);
params.put("password", pass);
Iterator entries = params.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
builder.appendQueryParameter(entry.getKey().toString(), entry.getValue().toString());
entries.remove();
}
requestBody = builder.build().getEncodedQuery();
try {
URL url = new URL(address);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream outputStream = new BufferedOutputStream(urlConnection.getOutputStream());
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, "utf-8"));
writer.write(requestBody);
writer.flush();
writer.close();
outputStream.close();
JSONObject jsonObject = new JSONObject();
InputStream inputStream;
// get stream
if (urlConnection.getResponseCode() < HttpURLConnection.HTTP_BAD_REQUEST) {
inputStream = urlConnection.getInputStream();
Log.w("URL", "Ok");
} else {
inputStream = urlConnection.getErrorStream();
Log.w("URL", "Bad request");
}
// parse stream
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String temp, response = "";
while ((temp = bufferedReader.readLine()) != null) {
response += temp;
}
// put into JSONObject
jsonObject.put("Content", response);
jsonObject.put("Message", urlConnection.getResponseMessage());
jsonObject.put("Length", urlConnection.getContentLength());
jsonObject.put("Type", urlConnection.getContentType());
JSONObject jsonObj = new JSONObject(response);
session_name = jsonObj.getString("session_name");
session_id = jsonObj.getString("sessid");
token = jsonObj.getString("token");
return jsonObject.toString();
} catch (IOException | JSONException e) {
return e.toString();
}
}
パスワードに関するチェックが表示されないため、Android/Javaの問題かどうかはわかりません。 – Denny
問題はサーバー側ではないと思いますか? –
あなたは正しいと思います。返信ありがとう –