Guest User

Untitled

a guest
Mar 19th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. package loginphp;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.net.HttpURLConnection;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10.  
  11. public class Loginphp {
  12.  
  13. public static void main(String[] args) throws MalformedURLException, IOException {
  14. String url = "http://localhost/login/login.php";
  15. String Parameters = "username=admin&password=admin";
  16. byte[] postdata = Parameters.getBytes("UTF-8");
  17. String useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0";
  18. URL urlLink = new URL(url);
  19.  
  20. HttpURLConnection urlConn = (HttpURLConnection) urlLink.openConnection();
  21. urlConn.setRequestMethod("POST");
  22. urlConn.setRequestProperty("User-Agent", useragent);
  23. urlConn.setRequestProperty("Content-Length", String.valueOf(postdata.length));
  24. urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  25. urlConn.setInstanceFollowRedirects(true);
  26. urlConn.setDoOutput(true);
  27. urlConn.getOutputStream().write(postdata);
  28.  
  29. System.out.println("Connecting to " + url);
  30. System.out.println("Response " + urlConn.getResponseMessage());
  31. System.out.println("Code " + urlConn.getResponseCode());
  32.  
  33. InputStream is = urlConn.getInputStream();
  34. InputStreamReader isr = new InputStreamReader(is);
  35. BufferedReader bis = new BufferedReader(isr);
  36.  
  37. String output;
  38.  
  39. while ((output = bis.readLine()) != null) {
  40.  
  41. System.out.println(" " + output);
  42. }
  43.  
  44. }
  45.  
  46. }
  47.  
  48. <?php
  49. include("config.php");
  50. session_start();
  51. $error = "";
  52. if($_SERVER["REQUEST_METHOD"] == "POST") {
  53. // username and password sent from form
  54.  
  55. $myusername = mysqli_real_escape_string($db,$_POST['username']);
  56. $mypassword = mysqli_real_escape_string($db,$_POST['password']);
  57.  
  58. $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
  59. $result = mysqli_query($db,$sql);
  60. $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
  61. $active = $row['active'];
  62.  
  63. $count = mysqli_num_rows($result);
  64.  
  65. // If result matched $myusername and $mypassword, table row must be 1 row
  66.  
  67. if($count == 1) {
  68. // session_register("myusername");
  69. $_SESSION['login_user'] = $myusername;
  70.  
  71. header("location: welcome.php");
  72. }else {
  73. $error = "Your Login Name or Password is invalid";
  74. }
  75. }
  76. ?>
  77. <html>
  78.  
  79. <head>
  80. <title>Login Page</title>
  81.  
  82. <style type = "text/css">
  83. body {
  84. font-family:Arial, Helvetica, sans-serif;
  85. font-size:14px;
  86. }
  87.  
  88. label {
  89. font-weight:bold;
  90. width:100px;
  91. font-size:14px;
  92. }
  93.  
  94. .box {
  95. border:#666666 solid 1px;
  96. }
  97. </style>
  98.  
  99. </head>
  100.  
  101. <body bgcolor = "#FFFFFF">
  102.  
  103. <div align = "center">
  104. <div style = "width:300px; border: solid 1px #333333; " align = "left">
  105. <div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
  106.  
  107. <div style = "margin:30px">
  108.  
  109. <form action = "" method = "post">
  110. <label>UserName :</label><input type = "text" name = "username" class = "box"/><br /><br />
  111. <label>Password :</label><input type = "password" name = "password" class = "box" /><br/><br />
  112. <input type = "submit" value = " Submit "/><br />
  113. </form>
  114.  
  115. <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
  116.  
  117. </div>
  118.  
  119. </div>
  120.  
  121. </div>
  122.  
  123. </body>
  124. </html>
  125.  
  126. header("HTTP/1.1 303 See Other");
  127. header("location: welcome.php");
Add Comment
Please, Sign In to add comment