기기에 로그인 자격증 명을 저장하려고합니다. 사용자가 앱을 열 때마다 로그인 할 필요가 없습니다. 그래서 여기에 문제가 있습니다. 암호 필드가 저장되고 있지만 전자 메일 필드에서도 암호가 저장되고 있습니다. 누군가 내가 뭘 잘못하고 있는지 말해 주시겠습니까? 아래 코드는 내 코드입니다. onResume 또는에서 onCreate에서 로그인 성공에기기에 로그인 자격증 명 저장
private static final String PREFS_NAME = "preferences";
//private static String password;
private static final String PREF_UNAME = "email";
private static final String PREF_PASSWORD = "Password";
Encryption mEncryption=null;
private final String DefaultUnameValue = "";
private String UnameValue;
private final String DefaultPasswordValue = "";
private String PasswordValue;
//private EditText editTextUsername;
private EditText editTextEmail;
private EditText editTextPassword;
private Button mSignUpBtn;
private Button mLoginButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_login);
mEncryption = new Encryption(getApplicationContext());
editTextEmail = (EditText) findViewById(R.id.login_page_id);
editTextPassword = (EditText) findViewById(R.id.login_page_password);
mSignUpBtn= (Button) findViewById(R.id.login_page_sign_up);
mSignUpBtn.setOnClickListener(this);
mLoginButton = (Button) findViewById(R.id.login_page_button);
mLoginButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == mLoginButton) {
LoginUser();
}
if (v==mSignUpBtn){
Intent intent=new Intent(LoginActivity.this,RegistrationActivity.class);
startActivity(intent);
}
}
private void LoginUser() {
final String email = editTextEmail.getText().toString().trim();
final String password = editTextPassword.getText().toString().trim();
StringRequest postStringRequest = new StringRequest(Request.Method.POST,LOGIN_API,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(LoginActivity.this, response, Toast.LENGTH_LONG).show();
Log.d(TAG,"Reponse Check :"+response);
ModelObject obj = new Gson().fromJson(response, ModelObject.class);
Log.d(TAG,"Object Check :"+obj);
Log.d(TAG,"Object Check :"+ModelObject.class);
Intent intent=new Intent(LoginActivity.this,RegistrationActivity.class);
startActivity(intent);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(LoginActivity.this, error.toString(), Toast.LENGTH_LONG).show();
Log.e(TAG,"Error Response Check :"+error);
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
Log.d(TAG,"For email :"+email);
Log.d(TAG,"For password :"+password);
//try {
Log.d(TAG,"My Credentials email URL Encoder: "+(mEncryption.AESEncode(email)));
Log.d(TAG,"My Credentials email URL DECODED: "+(mEncryption.AESDecode(mEncryption.AESEncode(email))));
params.put("data[User][email]",(mEncryption.AESEncode(email)));
Log.d(TAG,"My Credentials pass URL Encoder: "+(mEncryption.AESEncode(password)));
//Log.d(TAG,"My Credentials email URL DECODED: "+(mEncryption.AESDecode(mEncryption.AESEncode(password))));
params.put("data[User][password]",(mEncryption.AESEncode(password)));
Log.d(TAG,"Params :"+params);
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> headers = new HashMap<String, String>();
headers.put("Content-Type","application/x-www-form-urlencoded");
headers.put("UUID", "test");
headers.put("APPID", "2A192A0C22");
headers.put("USERID", "1");
headers.put("PLATFORM", "Andriod");
headers.put("APP_REQUEST", "1");
return headers;
}
};
//RequestQueue requestQueue = Volley.newRequestQueue(this);
RequestQueue queue = VolleySingleton.getInstance(this).getRequestQueue();
queue.add(postStringRequest);
}
@Override
public void onPause() {
super.onPause();
savePreferences();
}
@Override
public void onResume() {
super.onResume();
loadPreferences();
}
private void savePreferences() {
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
// Edit and commit
UnameValue = editTextEmail.getText().toString().trim();
PasswordValue = editTextPassword.getText().toString().trim();
//System.out.println("onPause save name: " + UnameValue);
// System.out.println("onPause save password: " + PasswordValue);
editor.putString(PREF_UNAME, UnameValue);
editor.putString(PREF_PASSWORD, PasswordValue);
editor.commit();
}
private void loadPreferences() {
SharedPreferences settings = getSharedPreferences(PREFS_NAME,
Context.MODE_PRIVATE);
// Get value
UnameValue = settings.getString(PREF_UNAME, DefaultUnameValue);
PasswordValue = settings.getString(PREF_PASSWORD, DefaultPasswordValue);
editTextEmail.setText(UnameValue);
editTextPassword.setText(PasswordValue);
System.out.println("onResume load name: " + UnameValue);
System.out.println("onResume load password: " + PasswordValue);
}
}