Advertisement
Guest User

Untitled

a guest
Jan 21st, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. public class LoginStudent extends Activity {
  2. Button b1;
  3. EditText e1, username;@
  4. Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. // TODO Auto-generated method stub
  7. super.onCreate(savedInstanceState);
  8. setContentView(R.layout.loginstudent);
  9. b1 = (Button) findViewById(R.id.button1);
  10. e1 = (EditText) findViewById(R.id.editText1);
  11. username = (EditText) findViewById(R.id.phone_no);
  12. b1.setOnClickListener(new View.OnClickListener() {@
  13. Override
  14. public void onClick(View arg0) {
  15. // TODO Auto-generated method stub
  16. if (e1.getText().length() == 0 || username.getText().length() == 0) {
  17. Toast.makeText(getBaseContext(), "Please Enter all the fields!!", Toast.LENGTH_LONG).show();
  18. } else {
  19. //Toast.makeText(getBaseContext(), "Registered successfully!", Toast.LENGTH_LONG).show();
  20. Intent i = new Intent(LoginStudent.this, Verify.class);
  21. startActivity(i);
  22. }
  23. }
  24. });
  25. }
  26. public void login(View view) {
  27. String username1 = username.getText().toString();
  28. new SigninActivity(this).execute(username1);
  29. }
  30. }
  31.  
  32. public class SigninActivity extends AsyncTask < String, Void, String > {
  33. private Context context;
  34. public SigninActivity(Context context) {
  35. this.context = context;
  36. }
  37. protected void onPreExecute() {
  38.  
  39. }
  40.  
  41. @Override
  42. protected String doInBackground(String...arg0) {
  43. try {
  44. String username = (String) arg0[0];
  45. String link = "http://example.com/try1.php?username=" + username;
  46. URL url = new URL(link);
  47. HttpClient client = new DefaultHttpClient();
  48. HttpGet request = new HttpGet();
  49. request.setURI(new URI(link));
  50. HttpResponse response = client.execute(request);
  51. BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  52. StringBuffer sb = new StringBuffer("");
  53. String line = "";
  54. while ((line = in .readLine()) != null) {
  55. sb.append(line);
  56. break;
  57. } in .close();
  58. return sb.toString();
  59. } catch (Exception e) {
  60. return new String("Exception: " + e.getMessage());
  61. }
  62. }
  63.  
  64. @SuppressLint("NewApi")@ Override
  65. protected void onPostExecute(String result) {
  66. if (result.isEmpty()) {
  67. System.out.println("user not present");
  68. } else {
  69. System.out.println(result);
  70. }
  71. }
  72. }
  73.  
  74. <?php
  75. class pswd {
  76. function generatePassword($length, $strength) {
  77. $vowels = 'aeuy';
  78. $consonants = 'bdghjmnpqrstvz';
  79. if ($strength & 1) {
  80. $consonants .= 'BDGHJLMNPQRSTVWXZ';
  81. }
  82. if ($strength & 2) {
  83. $vowels .= "AEUY";
  84. }
  85. if ($strength & 4) {
  86. $consonants .= '23456789';
  87. }
  88. if ($strength & 8) {
  89. $consonants .= '@#$%';
  90. }
  91.  
  92. $password = '';
  93. $alt = time() % 2;
  94. for ($i = 0; $i < $length; $i++) {
  95. if ($alt == 1) {
  96. $password .= $consonants[(rand() % strlen($consonants))];
  97. $alt = 0;
  98. } else {
  99. $password .= $vowels[(rand() % strlen($vowels))];
  100. $alt = 1;
  101. }
  102. }
  103. return $password;
  104. }
  105. }
  106. $con = mysqli_connect("example.com", "abc", "1234", "pqrs");
  107. if (mysqli_connect_errno($con)) {
  108. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  109. }
  110. $username = (int) $_GET['username'];
  111. echo $username;
  112. $result = mysqli_query($con, "SELECT * from login_stud where phone_no = '$username'");
  113. if ($row = mysqli_fetch_array($result)) {
  114. echo " user present";
  115. } else {
  116. $p = new pswd();
  117. $passwd = $p->generatePassword(4, 0);
  118. $result = mysqli_query($con, "Insert into login_stud (phone_no,password)values ('$username','$passwd')");
  119. }
  120. mysqli_close($con);
  121. ?>
  122.  
  123. <?php
  124. $con = mysqli_connect("example.com", "abc", "1234", "pqrs");
  125. if (mysqli_connect_errno($con)) {
  126. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  127. }
  128. //$username = (int) $_GET['username'];
  129. $username = $_GET['username'];
  130. echo $username;
  131. $result = mysqli_query($con, "SELECT * from login_stud where phone_no = '$username'");
  132. if ($row = mysqli_fetch_array($result)) {
  133. echo " user present";
  134. } else {
  135. $p = new pswd();
  136. $passwd = $p->generatePassword(4, 0);
  137. $result = mysqli_query($con, "Insert into login_stud (phone_no,password)values ('$username','$passwd')");
  138. }
  139. mysqli_close($con);
  140. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement