Ich erstelle eine native Android-App. Ich habe eine Login-Seite, bei der die Groß-/Kleinschreibung nicht beachtet wird.Android - App-Anmeldung vornehmen, Groß-/Kleinschreibung beachten
Beispiel: beide das Passwort Admin und Admin wird der Benutzer anmelden können. Dies sollte nicht möglich sein.
Der Login funktioniert. Mein Problem ist die Groß- und Kleinschreibung. Ich bin immer noch neu in Java und Android und nicht sicher, wo ich den Code setzen soll, um Groß- und Kleinschreibung zu berücksichtigen.
Sollte ich equalsIgnoreCase() verwenden?
Wenn ja, wie würden Sie in diesem Login equalsIgnoreCase() verwenden. Wo m \ u00f6chten Sie die Benutzeranmeldung mit der Rest-API
durchführen? Jede Hilfe wird verwendet.
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();
}
}
Ich sehe keine Überprüfung in Bezug auf das Passwort, so dass ich nicht sicher bin, ob dies ein Android/Java-Problem ist. – Denny
Glauben Sie nicht, dass das Problem auf der Serverseite liegt? –
Ich denke, du hast Recht. Danke für die Antwort –