Guest User

Untitled

a guest
Jul 6th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.96 KB | None | 0 0
  1. <?php
  2. session_start();
  3. header('Access-Control-Allow-Origin: *');
  4. header("Content-Type: text/html; charset=utf-8");
  5. include_once 'function.php';
  6.  
  7. $admin_login = '123';
  8. $admin_password = '123';
  9.  
  10. $module_mysql = new module_mysql();
  11. $module_db_host = 'localhost';
  12. $module_db_name = 'n96582pg_deadfld';
  13. $module_db_login = 'n96582pg_deadfld';
  14. $module_db_password = '89059325694';
  15.  
  16. $module_mysql -> connect_mysql($module_db_host, $module_db_login, $module_db_password, $module_db_name);
  17. ?>
  18.  
  19. <?php
  20.  
  21. class module_mysql {
  22.  
  23. function connect_mysql($db_host, $db_login, $db_password, $db_name){
  24.  
  25. mysql_connect($db_host, $db_login, $db_password, $db_name) or die ("Error connecting to MySQL: " . mysql_error());
  26. mysql_query("set names utf8") or die ("<br>Invalid query: " . mysql_error());
  27. mysql_select_db($db_name) or die ("<br>Invalid query: " . mysql_error());
  28.  
  29. }
  30.  
  31. function query_mysql($mysql_data_query, $type, $num) {
  32.  
  33. if ($data_query=mysql_query($mysql_data_query)) {
  34.  
  35. switch ($type) {
  36.  
  37. case 'num_row' : return mysql_num_rows($data_query); break;
  38. case 'accos' : return mysql_fetch_assoc($data_query); break;
  39. default: return $data_query;
  40.  
  41. }
  42.  
  43. } else {
  44.  
  45. print 'MySQL error: '.mysql_error();
  46. return false;
  47.  
  48. }
  49.  
  50. }
  51.  
  52. }
  53.  
  54. class module_functions {
  55.  
  56. function screening_function($function_data_screening) {
  57.  
  58. $function_data_screening = htmlspecialchars(trim($function_data_screening));
  59. return mysql_real_escape_string($function_data_screening);
  60.  
  61. }
  62.  
  63. function get_hash($login, $password, $level) {
  64.  
  65. switch($level){
  66.  
  67. case '1' : return md5(md5($this->screening_function($login . $password)) . 'Cv7X2WVdjSGEwNFInieora45WKRxpcef');
  68. case '2' : return md5(sha1(md5($this->screening_function($login . $password)) . sha1('Cv7X2WVdjSGEwNFInieora45WKRxpcef')));
  69.  
  70. }
  71.  
  72. }
  73.  
  74. function error_print($error) {
  75. $r=''."n".'';
  76. foreach($error as $key=>$value) {
  77. $r.=''.$value."n".'';
  78. }
  79. return $r.'';
  80. }
  81.  
  82. }
  83.  
  84. class module_global {
  85.  
  86. function module_newuser($login, $password, $received_hash) {
  87.  
  88. $module_functions = new module_functions();
  89. $module_mysql = new module_mysql();
  90.  
  91. $this_hash = $module_functions->get_hash($login, $password, '1');
  92.  
  93. if($this_hash == $received_hash){
  94. if(empty($login) or empty($password)) $error[] = 'All input fields are required.';
  95. if(strlen($login)<6 or strlen($login)>18) $error[] = 'Login length should be from 6 to 18 characters.';
  96. if(strlen($password)<6 or strlen($password)>20) $error[] = 'The password must be between 6 and 20 characters.';
  97. $login = $module_functions->screening_function($login);
  98. if($module_mysql->query_mysql("SELECT * FROM users WHERE login_user='".$login."';", 'num_row', '')!=0) $error[] = 'A user with this name already exists.'; else return 'good';
  99. } else $error[] = 'Invalid hash.';
  100.  
  101. if(isset($error)) return $module_functions->error_print($error);
  102.  
  103. }
  104.  
  105. function module_auth($login, $password, $received_hash) {
  106.  
  107. $module_functions = new module_functions();
  108. $module_mysql = new module_mysql();
  109.  
  110. $this_hash = $module_functions->get_hash($login, $password, '1');
  111.  
  112. if($this_hash == $received_hash){
  113.  
  114. if(!empty($login) or !empty($password)){
  115.  
  116. $password = md5(md5($module_functions->screening_function($password)) . 'Cv7X2WVdjSGEwNFInieora45WKRxpcef');
  117. $login = $module_functions->screening_function($login);
  118.  
  119. if ($module_mysql->query_mysql("SELECT * FROM `users` WHERE `login_user` = '".$login."' AND `password_user` = '".$password."';", 'num_row', '')==1) {
  120.  
  121. print md5($this_hash . 'Cv7X2WVdjSGEwNFInieora45WKRxpcef' . $this_hash) . ' | ';
  122. return true;
  123.  
  124. } elseif($module_mysql->query_mysql("SELECT * FROM `users` WHERE `login_user` = '".$login."';", 'num_row', 0)==1) {
  125.  
  126. $error[] = 'You did not enter the correct password.';
  127.  
  128. } else $error[] = 'User does not exist.';
  129.  
  130. } else $error[] = 'Enter data.';
  131.  
  132. } else $error[] = 'Invalid hash.';
  133.  
  134. if (isset($error)) print $module_functions->error_print($error); return false;
  135.  
  136. }
  137.  
  138.  
  139. function module_reg($login, $password, $received_hash){
  140.  
  141. $module_functions = new module_functions();
  142. $module_mysql = new module_mysql();
  143.  
  144. if (($this->module_newuser($login, $password, $received_hash)) == 'good') {
  145.  
  146. $password = md5(md5($module_functions->screening_function($password)) . 'Cv7X2WVdjSGEwNFInieora45WKRxpcef');
  147. $login = $module_functions->screening_function($login);
  148.  
  149. if ($module_mysql->query_mysql("INSERT INTO `users` (`id_user`, `login_user`, `password_user`) VALUES (NULL, '".$login."', '".$password."');", '', '')) {
  150.  
  151. print md5($this_hash . 'Cv7X2WVdjSGEwNFInieora45WKRxpcef' . $this_hash) . ' | ';
  152. return true;
  153.  
  154. } else {
  155.  
  156. print 'An error occurred while registering a new user. Please contact the property'; return false;
  157.  
  158. }
  159.  
  160. } else print $this->module_newuser($login, $password, $received_hash); return false;
  161.  
  162. }
  163.  
  164. }
  165.  
  166. ?>
  167.  
  168. <?php
  169.  
  170. include_once 'config.php';
  171.  
  172. $module_global = new module_global();
  173.  
  174. if(isset($_POST['type']) && isset($_POST['login']) &&
  175.  
  176. isset($_POST['password']) && isset($_POST['hash'])){
  177.  
  178. switch($_POST['type']){
  179.  
  180. case 'module_auth' :
  181. if ($module_global->module_auth($_POST['login'], $_POST['password'], $_POST['hash'])) {
  182. echo 'true'; break;
  183. } else {
  184. echo 'false'; break;
  185. }
  186.  
  187. case 'module_reg' :
  188. if ($module_global->module_reg($_POST['login'], $_POST['password'], $_POST['hash'])) {
  189. echo 'true'; break;
  190. } else {
  191. echo 'false'; break;
  192. }
  193.  
  194. }
  195.  
  196. } else print 'PHP error: invalid data';
  197.  
  198.  
  199. ?>
Add Comment
Please, Sign In to add comment