Advertisement
roooliveira

Untitled

Apr 13th, 2017
591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Register
  5. {
  6. private $CurrentChannel = '01';//Canal atual
  7. private $AccountDir = 'C://Users//Administrator//Desktop//Server//DBSrv//run//account';//Accounts
  8. private $AccountDir2 = 'C:\Users\Administrator\Desktop\Server\DBSrv\run\account';//Accounts
  9. private $Mod = true;//TRUE para release de pobre, false pra do seitbnao
  10. private $ImportUser = 'C:/Users/Administrator/Desktop/Server/Common/ImportUser';//Cadastro
  11. private $UpdateAcount = 'C://Users//Administrator//Desktop//Server//Common//UpdateUser';//Troca de Senha
  12. public $err = array(
  13. 'Usuário deve conter de 4 a 16 caracteres alfanuméricos<br>',
  14. 'Senha deve conter de 4 a 12 caracteres alfanuméricos<br>',
  15. 'Nome deve conter de 4 a 24 caracteres alfanuméricos<br>',
  16. 'Email deve ser um email válido<br>',
  17. 'Codigo de recuperacao deve conter 9 a 16 digitos numéricos<br> ',
  18. 'Digite TOW ONLINE <br>',
  19. 'Conta está em uso <br>',
  20. 'Login ou senha não podem ficar em branco <br>',
  21. 'Conta criada com sucesso <br>',
  22. 'Nova senha não pode ficar em branco <br>',
  23. 'Nova senha deve conter de 4 a 12 caracteres alfanuméricos<br>',
  24. 'Conta não existe<br>',
  25. 'Senha alterada com sucesso<br>',
  26. 'Senha não confere!<br>'
  27.  
  28. );
  29.  
  30.  
  31. function __construct($Channel = '01')
  32. {
  33. $this->CurrentChannel = $Channel;
  34. }
  35.  
  36.  
  37. public function Validar($user = 'Servidor', $pass = 'senha',$Email ='servidor@wyd.com',$RealName ='Servidor Unico',$Telephone = '12345678912345',$Address = 'São Paulo')
  38. {
  39.  
  40. $user = trim($user);
  41. $pass = trim($pass);
  42. if(!preg_match('/^[0-9a-zA-Z]{4,16}$/i',$user))
  43. {
  44. echo $this->err[0];
  45. return false;
  46. }
  47. if(!preg_match('/^[0-9a-zA-Z]{4,12}$/i',$pass))
  48. {
  49. echo $this->err[1];
  50. return false;
  51. }
  52. if (!filter_var($Email, FILTER_VALIDATE_EMAIL))
  53. {
  54. echo $this->err[3];
  55. return false;
  56. }
  57. if(strlen($RealName) < 5 || strlen($RealName) >= 24)
  58. {
  59. echo $this->err[2];
  60. return false;
  61. }
  62. include_once("config.db.site.php");
  63. $loginacc = ($_POST['login']);
  64. $senhaacc = ($_POST['senha']);
  65. $emailacc = ($_POST['email']);
  66. $codigoacc = ($_POST['telefone']);
  67. try {
  68. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  69. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  70. $sql ="INSERT INTO t_account (name, pw2, email, codigo)
  71. VALUES ('$loginacc', '$senhaacc', '$emailacc', '$codigoacc')";
  72. $conn->exec($sql);
  73. echo '
  74. <script type="text/javascript">
  75.  
  76. alert("Conta cadastrada com sucesso.");
  77.  
  78.  
  79. </script>
  80. ';
  81. }
  82. catch(PDOException $e)
  83. {
  84. echo $sql . "<br>" . $e->getMessage();
  85. }
  86.  
  87. $conn = null;
  88. return true;
  89. }
  90. public function InitialDir($Login)
  91. {
  92. $ini = substr($Login,0,1);
  93. if(is_numeric($ini))
  94. $ini = "etc";
  95. return $ini;
  96. }
  97. public function Trocar_Senha($user, $pass,$NewPass)
  98. {
  99. if(empty($user)|| empty($pass) || empty($NewPass))
  100. {
  101. if(empty($NewPass))
  102. echo $this->err[9];
  103. else
  104. echo $this->err[7];
  105.  
  106. return false;
  107. }
  108. $account = $this->AccountDir2.'\\'.$this->InitialDir($user).'\\'.$user;
  109.  
  110. if(!file_exists($account))
  111. {
  112. echo $this->err[11];
  113. return false;
  114. }
  115. if(!$this->Validar($user, $pass))
  116. return false;
  117.  
  118. if(!$this->Validar($user, $NewPass))
  119. return false;
  120.  
  121. $Buffer = $this->OpenAccount($account);
  122. if(!$Buffer)
  123. {
  124. echo 'Erro ao abrir conta!';
  125.  
  126. return false;
  127. }
  128.  
  129. $PwdFile = trim(hex2bin(substr($Buffer,32,28)));
  130.  
  131. if(strcmp($PwdFile,$pass))
  132. {
  133. echo $this->err[13];
  134. return false;
  135. }
  136.  
  137. if($this->Mod == false)
  138. $account2 = $this->UpdateAcount.'\\'. $this->CurrentChannel.'\\update\\'.$user;
  139. else
  140. $account2 = $this->UpdateAcount.'\\update\\'.$user;
  141.  
  142. $fp = fopen($account2, "wt");
  143. $escreve = fwrite($fp, "$user\n");
  144. $escreve = fwrite($fp, "$NewPass\n");
  145. fclose($fp);
  146. echo $this->err[12];
  147. return true;
  148. }
  149. public function Registrar($user, $pass,$email,$Name,$tel,$Addr)
  150. {
  151. if(empty($user)|| empty($pass))
  152. {
  153. echo $this->err[7];
  154. return false;
  155. }
  156. if(!$this->Validar($user, $pass,$email,$Name,$tel,$Addr))
  157. return false;
  158. $account = $this->AccountDir.'\\'.$this->InitialDir($user).'\\'.$user;
  159. $account2 = $this->ImportUser.'\\'.$user;
  160. if(file_exists($account))
  161. {
  162. echo $this->err[6];
  163. return false;
  164. }
  165. else
  166. {
  167. $Bonus = 0;
  168.  
  169. $ssn = rand()%1001;
  170. $ssn2 = rand()%1001;
  171. $user = strtoupper($user);
  172. $email = strtoupper($email);
  173. $Name = strtoupper($Name);
  174. $Addr = strtoupper($Addr);
  175. //id, pass, name, ssn1, ssn2, email, tel, addr, bonus
  176. $fp = fopen($account2, "wt");
  177. $escreve = fwrite($fp, "$user\n");
  178. $escreve = fwrite($fp, "$pass\n");
  179. $escreve = fwrite($fp, "$Name\n");
  180. $escreve = fwrite($fp, "$ssn\n");
  181. $escreve = fwrite($fp, "$ssn2\n");
  182. $escreve = fwrite($fp, "$email\n");
  183. $escreve = fwrite($fp, "$tel\n");
  184. $escreve = fwrite($fp, "$Addr\n");
  185. $escreve = fwrite($fp, "$Bonus\n");
  186. fclose($fp);
  187.  
  188. echo $this->err[8];
  189. return true;
  190.  
  191. }
  192. }
  193. public function OpenAccount($account)
  194. {
  195.  
  196. if(file_exists($account))
  197. {
  198. $open = @fopen($account,'r');
  199. $leitura = @fread($open, filesize($account));
  200. return trim(strtoupper(bin2hex($leitura)));
  201. }
  202. else
  203. return 0;
  204. }
  205. public function hexTobin($data)
  206. {
  207. return pack("H".strlen($data),$data);
  208. }
  209. public function inverterhex($data)
  210. {
  211. $tamanho=strlen($data);
  212. if(($tamanho % 2)!=0)
  213. {
  214. $data="0".$data;
  215. }
  216. $data=wordwrap($data, 2, "/", true);
  217. $explode=explode("/", $data);
  218. $a=0;
  219. for($i=(count($explode)-1); $i>=0; $i--)
  220. {
  221. $join[$a]=$explode[$i];
  222. $a++;
  223. }
  224. $data=implode("", $join);
  225. return $data;
  226. }
  227. public function hex2num($data)
  228. {
  229. return hexdec($this->inverterhex($data));
  230. }
  231. public function num2hex($data)
  232. {
  233. return $this->inverterhex(dechex($data));
  234. }
  235. }
  236.  
  237.  
  238. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement