-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.java.txt
115 lines (98 loc) · 4.52 KB
/
MainActivity.java.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.example.securesharedpreference;
import androidx.appcompat.app.AppCompatActivity;
import androidx.security.crypto.EncryptedSharedPreferences;
import androidx.security.crypto.MasterKeys;
/////////////////////////////////Made By Divyam Oza(OD)////////////////////////////
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import java.io.IOException;
import java.security.GeneralSecurityException;
public class MainActivity extends AppCompatActivity {
EditText et_username,et_password;
Button submitbtn;
TextView textView;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
Boolean savelogin;
CheckBox savecheck;
ImageView logo,unmlogo,passlogo;
/////////////////////////////////Made By Divyam Oza(OD)////////////////////////////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_username = findViewById(R.id.et_username);
et_password = findViewById(R.id.et_password);
submitbtn = findViewById(R.id.btnsave);
savecheck = findViewById(R.id.rememberme);
logo = findViewById(R.id.logo);
unmlogo = findViewById(R.id.unmlogo);
passlogo = findViewById(R.id.passlogo);
//IMAGES get through Glide//
Glide.with(getApplicationContext()).load("https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Ei-sc-github.svg/768px-Ei-sc-github.svg.png").into(logo);
Glide.with(getApplicationContext()).load("https://i.pinimg.com/originals/e4/fb/d4/e4fbd41a84015e49d95baddee5275043.png").into(unmlogo);
Glide.with(getApplicationContext()).load("https://www.lockitsolutions.com/blog/wp-content/uploads/2015/05/lockitLogo.png").into(passlogo);
//IMAGES get through Glide//
try {
String masterKeys = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
sharedPreferences = EncryptedSharedPreferences.create("FILE",
masterKeys,
getApplicationContext(),
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM);
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
/////////////////////////////////Made By Divyam Oza(OD)////////////////////////////
editor =sharedPreferences.edit();
submitbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
login();
}
});
savelogin = sharedPreferences.getBoolean("savelogin",true);
if (savelogin==true)
{
et_username.setText(sharedPreferences.getString("username",null));
et_password.setText(sharedPreferences.getString("password",null));
}
if(et_username.getText().toString().equals("divyamoza") && et_password.getText().toString().equals("divyam123"))
{
Intent intent = new Intent(getApplicationContext(),MainActivity2.class);
startActivity(intent);
}
/////////////////////////////////Made By Divyam Oza(OD)////////////////////////////
}
private void login()
{
String username = et_username.getText().toString();
String password = et_password.getText().toString();
if(username.equals("divyamoza") && password.equals("divyam123"))
{
Toast.makeText(this, "Welcome", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),MainActivity2.class);
startActivity(intent);
}
/////////////////////////////////Made By Divyam Oza(OD)////////////////////////////
if(savecheck.isChecked())
{
editor.putBoolean("savelogin",true);
editor.putString("username",username);
editor.putString("password",password);
editor.commit();
}
/////////////////////////////////Made By Divyam Oza(OD)////////////////////////////
}
}