Added read password from file.
This commit is contained in:
parent
f36506d92e
commit
7ac96f9de4
@ -12,15 +12,40 @@ import android.widget.EditText;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
TextView response;
|
TextView response;
|
||||||
Button button;
|
Button button;
|
||||||
Button restartpassword;
|
Button restartpassword;
|
||||||
private EditText textPassword;
|
private EditText textPassword;
|
||||||
private View viewPassword;
|
private View viewPassword;
|
||||||
|
private static final String filename = "passwd.txt";
|
||||||
|
|
||||||
|
public String readFile(String filename) throws IOException {
|
||||||
|
String content = null;
|
||||||
|
File file = new File(filename); // For example, foo.txt
|
||||||
|
FileReader reader = null;
|
||||||
|
try {
|
||||||
|
reader = new FileReader(file);
|
||||||
|
char[] chars = new char[(int) file.length()];
|
||||||
|
reader.read(chars);
|
||||||
|
content = new String(chars);
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if(reader != null){
|
||||||
|
reader.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -42,15 +67,20 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
button.setOnClickListener(new OnClickListener() {
|
button.setOnClickListener(new OnClickListener() {
|
||||||
|
private final String filename = getFilesDir() + "/passwd.txt";
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
response.setText(textPassword.getText());
|
response.setText(textPassword.getText());
|
||||||
if (textPassword.getText().toString().equals("123")) {
|
try {
|
||||||
|
if (textPassword.getText().toString().equals(readFile(filename).toString())) {
|
||||||
Intent myIntent2 = new Intent(MainActivity.this,
|
Intent myIntent2 = new Intent(MainActivity.this,
|
||||||
Noto.class);
|
Noto.class);
|
||||||
startActivity(myIntent2);
|
startActivity(myIntent2);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user