Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. private void btEntrar_Click(object sender, EventArgs e)
  2. {
  3. String login, senha, postData, requestMethod = "POST", contentType = "application/x-www-form-urlencoded", responseFromServer = null;
  4. String urlLogin = "http://192.168.1.107/knowledgems/accounts/login.php";
  5.  
  6. login = tbLogin.Text;
  7. senha = tbSenha.Text;
  8. postData = "param1=" + login + "&param2=" + senha;
  9. byte[] byteArray = Encoding.UTF8.GetBytes(postData);
  10. WebRequest request = WebRequest.Create(urlLogin);
  11. WebResponse response;
  12. Stream dataStream;
  13. StreamReader reader;
  14.  
  15. //Send request
  16. request.Method = requestMethod;
  17. request.ContentType = contentType;
  18. request.ContentLength = byteArray.Length;
  19. dataStream = request.GetRequestStream();
  20. dataStream.Write(byteArray, 0, byteArray.Length);
  21. dataStream.Close();
  22.  
  23. //Get response
  24. response = request.GetResponse();
  25. dataStream = response.GetResponseStream();
  26. reader = new StreamReader(dataStream);
  27. responseFromServer = reader.ReadToEnd();
  28. reader.Close();
  29. dataStream.Close();
  30. response.Close();
  31.  
  32. if (responseFromServer.Equals("SUCCESS"))
  33. MessageBox.Show("Login efetuado.");
  34. else
  35. MessageBox.Show("Login não efetuado." + responseFromServer);
  36. } //btEntrar
  37.  
  38. <?php
  39. require_once 'connection.php';
  40. header('Content-Type: application/form-data');
  41.  
  42. class User {
  43. private $db;
  44. private $connection;
  45.  
  46. function __construct(){
  47. $this->db = new DB_Connection();
  48. $this->connection = $this->db->get_connection();
  49. } //__construct
  50.  
  51. public function does_user_exist($username,$password){
  52. $query = "SELECT * FROM users WHERE user_username = '$username' AND user_password = '$password'";
  53. $result = mysqli_query($this->connection,$query);
  54. if(mysqli_num_rows($result) > 0){
  55. echo "SUCCESS";
  56. } //if
  57. else {
  58. echo "ERRO&101";
  59. } //else
  60. mysqli_close($this->connection);
  61. } //does_user_exist
  62.  
  63. } //class
  64.  
  65. $user = new User();
  66. if (isset($_POST['param1'],$_POST['param2'])){
  67. $username = $_POST['param1'];
  68. $password = $_POST['param2'];
  69. if(!empty($username) && !empty($password)){
  70. //$encrypted_password = md5($password);
  71. $user -> does_user_exist($username,$password);
  72. }
  73. else {
  74. echo "ERRO&100";
  75. } //else
  76. } //if
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement