H
H
hudrogen2014-05-19 13:43:17
Java
hudrogen, 2014-05-19 13:43:17

Android programming. How to implement a password-protected login to the application?

Hello! Wrote a simple program for android encryption / decryption of text - symmetric encryption "DES". In the main window in EditText1, the user sets the master key, then using Button1 the key is entered into the key variable in the encryption/decryption class. In EditText2 the user writes the text to be encrypted/decrypted. Clicks on the button Button2 and below in the TextView1 and TextView2 elements, the encrypted/decrypted text is displayed, respectively.
I have a task so that when the user first starts the program, the user sets a password to enter the program. Further, at each launch, the program would require you to enter this password, and if the password is correct, then the main Activity would open, if the password is not correct, then a pop-up message would appear that the password is not correct. (Typical android safe in general)
How to implement so that when the program is launched, depending on some conditions, one Activity is launched, with others another Activity?
Main Activity Code

package com.example.crypto;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.os.Build;
import com.example.crypto.SimpleDESCryptoProvider;  //класс для работы с шифрованием/дешифрованием

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

public void onKey (View v){ // при нажатии на кнопку 1

EditText et = (EditText) findViewById(R.id.editText1);
//if (!ec.getText().toString().equals("FGSJDFGK"))
String str1 =   et.getText().toString();
SimpleDESCryptoProvider.seed = str1;//задается мастерключ


}
public void onEnCrypt (View v){ //при нажатии на кнопку 2
TextView ec = (TextView)findViewById(R.id.textViewEnCrypted);
TextView dc = (TextView)findViewById(R.id.textViewDeCrypted);
EditText ep = (EditText) findViewById(R.id.editText2);
String str2 = ep.getText().toString();
String d = SimpleDESCryptoProvider.encrypt(str2);  //метод для шифрования
ec.setText("Зашифолванный текст= " + d);
dc.setText("Расшифрованный текст= " +SimpleDESCryptoProvider.decrypt(d));  // метод для расшифрования

}

}

Here is a link to the project just in case: yadi.sk/d/jqp2Ue-6QhB7H

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2014-05-19
@onepavel

Store application state in SharedPreferences. When you start, read and react in the way you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question