2017-04-25 4 views
-1

私はネイティブの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(); 
     } 
    } 
+1

パスワードに関するチェックが表示されないため、Android/Javaの問題かどうかはわかりません。 – Denny

+1

問題はサーバー側ではないと思いますか? –

+0

あなたは正しいと思います。返信ありがとう –

答えて

1

まず、ログインロジックとしてBasic Auth Systemを使用してください。これにより、他のAPI呼び出しに使用するトークンが返されます。 RetrofitとOkHttpClientを見てください。 また、ネットワーク接続ロジックはすべて別のクラスにある必要があります。

あなたのケースでは、サーバー側で大文字と小文字の区別をテストする必要があります。 あなたのアンドロイドアプリケーションでは、資格情報の妥当性について忘れている必要があります。それはユーザーから受け取り、それをサーバーのAPIに渡します。

+0

ありがとう、これは非常に有用だった。 –

関連する問題