Advertisement
jared314

Untitled

Aug 6th, 2015
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2.  
  3. $dbConn = mysql_connect('localhost', '****', '****')
  4. or die(print_r(mysql_error()));
  5.  
  6. mysql_select_db('base_logger') or die(print_r(mysql_error()));
  7.  
  8. $username = $_POST['user'];
  9. $password = $_POST['pass'];
  10. $name = $_POST['name'];
  11. $id = $_POST['id'];
  12.  
  13. signIn($username, $password, $name, $dbConn, $id);
  14.  
  15. function signIn($username, $password, $name, $dbConn, $id) {
  16.  
  17. $username = htmlspecialchars($username);
  18. $password = htmlspecialchars($password);
  19.  
  20. $salt = '';
  21. $query = "select salt from users where username = '".dbEsc($username). "';";
  22. $result = mysql_query($query);
  23. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  24. $salt = $row['salt'];
  25.  
  26. $hash = sha1($salt.$password);
  27.  
  28. $query2 = "select user_id from users where username = '" . dbEsc($username) . "' AND password = '" . $hash . "';";
  29.  
  30. $result2 = mysql_query($query2);
  31. $row2 = mysql_fetch_array($result2, MYSQL_ASSOC);
  32.  
  33. if ($row2['user_id'] != '') {
  34. createToken($dbConn, $row2['user_id'], $name, $id, $username);
  35. } else {
  36. echo 'error';
  37. }
  38. }
  39.  
  40. function createToken($dbConn, $user_id, $name, $id, $username) {
  41. $token = rand().rand().rand().rand();
  42. $query = "INSERT INTO tokens (token, user_id, computer_name, computer_id) VALUES ('".$token."', '".dbEsc($user_id)."', '".dbEsc($name)."', '".dbEsc($id)."')";
  43. $result = mysql_query($query);
  44. if ($result) {
  45. echo $token;
  46. } else {
  47. echo 'error';
  48. }
  49. }
  50.  
  51. function dbEsc($theString) {
  52. $theString = mysql_real_escape_string($theString);
  53. return $theString;
  54. }
  55.  
  56. function dbError(&$xmlDoc, &$xmlNode, $theMessage) {
  57. $errorNode = $xmlDoc->createElement('mysqlError', $theMessage);
  58. $xmlNode->appendChild($errorNode);
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement