forked from hussien89aa/AndroidVulnerability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStorage.txt
124 lines (105 loc) · 4.09 KB
/
Storage.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
116
117
118
119
120
121
/*
store data in the app
*/
1- // XML layout
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="60dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name:"
android:id="@+id/textView" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/etUserName" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PassWord:"
android:id="@+id/password" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/etPassword" />
</LinearLayout>
</LinearLayout>
2-- unsecure code
// shared references files name
public static final String MyPREFERENCES = "MyPrfLogin" ;
// key for user name
public static final String UserName = "UserNameKey";
// key for password
public static final String Password = "PasswordKey";
// shared references instance to access to virtual file
SharedPreferences sharedpreferences;
// input text name
EditText etUserName;
// input text password
EditText etPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// initialize user name instance with the real input in xml
etUserName=(EditText)findViewById(R.id.etUserName);
// initialize password instance with the real input in xml
etPassword=(EditText)findViewById(R.id.etPassword);
// // initialize shared references
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
// access to the floating button
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
// listen to floating button when click
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// save data
// enable start editing file
SharedPreferences.Editor editor = sharedpreferences.edit();
// add user name
editor.putString(UserName, etUserName.getText().toString());
// add password
editor.putString(Password, etPassword.getText().toString());
// save the update data
editor.commit();
//display message saved
Toast.makeText(MainActivity.this, "Data is Saved", Toast.LENGTH_LONG).show();
}
});
}
//secure code encript
// cipher encryption add shift for key
/*
// cipher encryption add shift for key
cipher(“hussein”, 10) // result “r }}osx”
// cipher Decryptions
cipher(“r }}osx”, -10) / result “Hussein”
*/
String cipher(String msg, int shift){
String s = "";
int len = msg.length(); // get string length
for(int x = 0; x < len; x++){
char c = (char)(msg.charAt(x) + shift); // shift every character
s += c; // append the characters
}
return s;
}