NotepadActivity.new_password
and it is not encapsulated. Meaning, every programmer may view, edit, access the password within any part of the project.3. The password is stored locally, in the cache
Confidential — authorized people have the access
Anyone who has the access to the project has the access to the password of a user. For instance, a project may be an Open Source and hosted on GitHub. Unless the GitHub sensitive data feature get triggered and remove the very same data, this password would be place in GitHub for everyone’s view
Integrity — users aren’t capable of unintentional editing of data.
In this project a programmer may unintentional editing of data.
Availability — it is about available of information
public static String new_password = "1234";
maybe it will be a good idea to code like this privatestatic String new_password = "1234";
constructor
or setters
public class MainActivity extends AppCompatActivity {
EditText password;
private Button button;
public static String correct_password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
password = findViewById(R.id.password);
button = (Button) findViewById(R.id.login);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
correct_password = NotepadActivity.new_password;
//validate password
if (TextUtils.isEmpty(password.getText().toString())) {
Toast.makeText(MainActivity.this, "Empty input", Toast.LENGTH_LONG).show();
}
else if (password.getText().toString().equals(correct_password)) {
Toast.makeText(MainActivity.this, "Correct password", Toast.LENGTH_LONG).show();
openNotepad();
}
else
Toast.makeText(MainActivity.this, "Invalid password", Toast.LENGTH_LONG).show();
}
});
}
public void openNotepad() {
Intent intent = new Intent(this, NotepadActivity.class);
startActivity(intent);
}
}
public class NotepadActivity extends AppCompatActivity {
private TextView textView;
private EditText editText;
private Button saveButton;
private Button changeButton;
public static final String TEXT = "message";
public static final String SHARED_PREFS = "sharedPrefs";
public static String text;
public static String new_password = "1234";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notepad);
textView = (TextView) findViewById(R.id.text_view);
editText = (EditText) findViewById(R.id.edit_text);
saveButton = (Button) findViewById(R.id.save_button);
changeButton = (Button) findViewById(R.id.change_password);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText(editText.getText().toString());
saveData();
}
});
changeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new_password = editText.getText().toString();
savePassword();
}
});
loadData();
updateView();
}
public void saveData() {
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(TEXT, textView.getText().toString());
editor.apply();
Toast.makeText(this,"Data saved", Toast.LENGTH_SHORT).show();
}
public void savePassword() {
Toast.makeText(this,"Password changed to: "+ new_password, Toast.LENGTH_SHORT).show();
}
public void loadData() {
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
text = sharedPreferences.getString(TEXT, "");
}
public void updateView() {
textView.setText(text);
}
}
PatternLockView
from jCenter repository ****is deprecated.jCenter is no longer be available for non-Artifactory clients. This means by the end of March 2021, publishing new packages to Bintray will no longer be allowed
public class** MainActivity **extends** AppCompatActivity
in the run()
method we have the same code in the both if-else scenariossharedPreferences.getString
PatternLockView
. Moreover, the creators do not intend to transfer the library to Maven repository. The last changes to the library were in 2017 https://github.com/aritraroy/PatternLockViewMainActivity
has the same if-else code, thus, a user or unauthorized person has the access to the program despite entering the wrong password
import com.andrognito.patternlockview.PatternLockView;
import com.andrognito.patternlockview.listener.PatternLockViewListener;
import com.andrognito.patternlockview.utils.PatternLockUtils;
import java.util.List;
public class CreatePasswordActivity extends AppCompatActivity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// loading is given
SharedPreferences sharedPreferences = getSharedPreferences("PREFS", 0);
String password = sharedPreferences.getString("password", "0");
if (password.equals("0")) {
// Intent to navigate to Create Password Screen
Intent intent = new Intent(getApplicationContext(), CreatePasswordActivity.class);
startActivity(intent);
finish();
} else {
// Intent to navigate to Input Password Screen
Intent intent = new Intent(getApplicationContext(), InputPasswordActivity.class);
startActivity(intent);
finish();
}
}
}, 2000);
}
}
public class MainActivity extends AppCompatActivity {
Button changepassword;
Button notechange;
TextView thenote;
String notee;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences settings = getSharedPreferences("PREFS", 0);
notee = settings.getString("note", "");
changepassword = (Button) findViewById(R.id.changepassword);
notechange = (Button) findViewById(R.id.notechange);
thenote = (TextView) findViewById(R.id.thenote);
thenote.setText(notee);
//ability to cahnge the password on the main screen
changepassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), NewPasswordActivity.class);
startActivity(intent);
finish();
}
});
notechange.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent2 = new Intent(getApplicationContext(), MessageChangeActivity.class);
startActivity(intent2);
finish();
}
});
}
}
public class NewPasswordActivity extends AppCompatActivity {
EditText passwordcreating;
Button confirm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_password);
passwordcreating = (EditText) findViewById(R.id.passwordcreating);
confirm = (Button) findViewById(R.id.confirm);
confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = passwordcreating.getText().toString();
if(text.equals("")){
Toast.makeText(NewPasswordActivity.this, "No Password Entered", Toast.LENGTH_SHORT).show();
}
else{
SharedPreferences settings = getSharedPreferences("PREFS", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("password", text);
editor.apply();
//small string input
Toast.makeText(NewPasswordActivity.this, "New Password Set", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
finish();
}
}
});
}
}
There are many licenses with slight variations, which might be overwhelming sometimes. Personally, I have…