我正在構建原生Android應用程序。我有一個不區分大小寫的登錄頁面。Android - 使應用程序登錄,區分大小寫
例子:兩個密碼的管理員和管理將允許用戶登錄。這應該是不可能的。
登錄正在工作。我的問題是區分大小寫。我對Java和Android還是一個新手,並不確定在哪裏放置代碼以區分大小寫。
我應該使用equalsIgnoreCase()嗎?
如果是這樣,你將如何在這個登錄中使用equalsIgnoreCase()。你在哪裏主持用戶登錄與其他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
你不覺得這個問題是在服務器端嗎? –
我認爲你是對的。感謝您的回覆 –