Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. public class LoginControl extends Activity {
  2. private DBControl db = new DBControl(this);
  3. int counter = 2;
  4. Button login = null;
  5.  
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. super.onCreate(savedInstanceState);
  9. setContentView(R.layout.loginview);
  10.  
  11.  
  12. Button register = (Button) findViewById(R.id.btnCreateA);
  13. login = (Button) findViewById(R.id.btnLogin);
  14. login.setOnClickListener(new View.OnClickListener() {
  15. @Override
  16. public void onClick(View v) {
  17. try {
  18. EditText a = (EditText) findViewById(R.id.etUser);
  19. EditText b = (EditText) findViewById(R.id.etPassword);
  20. String user = a.getText().toString();
  21. String pass = b.getText().toString();
  22. String confirm = db.getUserPass(user);
  23. if (user.equals("") || pass.equals("")) {
  24. Toast passed = Toast.makeText(LoginControl.this, "Please input required fields.", Toast.LENGTH_LONG);
  25. passed.show();
  26. } else if (pass.equals(confirm)) {
  27. Toast passed = Toast.makeText(LoginControl.this, "Sucess!", Toast.LENGTH_LONG);
  28. passed.show();
  29. Intent intent = new Intent(LoginControl.this, HomeControl.class).putExtra("Music", false);
  30. startActivity(intent);
  31. finish();
  32.  
  33. } else if (counter == 0)
  34. // Disable button after 3 failed attempts
  35. {
  36.  
  37. login.setEnabled(false);
  38.  
  39. Toast alert = Toast.makeText(LoginControl.this, "Login Disabled for 5 mins", Toast.LENGTH_LONG);
  40. alert.show();
  41.  
  42. final Handler handler = new Handler();
  43. handler.postDelayed(new Runnable() {
  44. @Override
  45. public void run() {
  46. login.setEnabled(true);
  47. counter = 2;
  48. }
  49. }, 30000);
  50. } else {
  51. Toast passed = Toast.makeText(LoginControl.this, "Username or password don't match!", Toast.LENGTH_LONG);
  52. counter--;
  53. passed.show();
  54. }
  55. } catch (Exception e) {
  56. Toast passed = Toast.makeText(LoginControl.this, e.toString(), Toast.LENGTH_LONG);
  57. passed.show();
  58. }
  59. }
  60. });
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement