Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2. //--Powered by DarkCoreCMS
  3. //--Website: http://mmltools.com
  4. //--Author: Marco aka (Darksoke)
  5.  
  6. function connect($ip, $user, $password, $database){
  7. $con = mysqli_connect($ip, $user, $password, $database) or die('try again in some minutes, please');
  8. if (!$con)
  9. printf("Connect failed: %s\n", mysqli_connect_error());
  10. //exit();
  11. else
  12. return $con;
  13. }
  14. function encrypt($username, $password)
  15. {
  16. $password = sha1(strtoupper($username) . ":" . strtoupper($password));
  17. $password = strtoupper($password);
  18. return $password;
  19. }
  20. function check_user_exist($username){
  21. global $db_ip, $db_user, $db_password, $db_auth;
  22. $con = connect($db_ip, $db_user, $db_password, $db_auth);
  23. $stmt = $con->prepare("SELECT * FROM account WHERE `username`=?");
  24. $stmt->bind_param("s", $username);
  25. $stmt->execute();
  26. $stmt->store_result();
  27. return $stmt->num_rows;
  28. $stmt->close();
  29. $con->close();
  30. }
  31. function clean($string) {
  32. $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
  33.  
  34. return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
  35. }
  36. function register_user($username, $password, $repassword, $email){
  37. if ($password != $repassword){
  38. echo "<font color='#ff0000;'>Passwords do not match. <br></font>";
  39. return;
  40. }
  41. else
  42. $new_password = encrypt($username,$password);
  43.  
  44. $sql = "INSERT INTO `account` (`username`, `sha_pass_hash`) VALUES (?,?)";
  45. global $db_ip, $db_user, $db_password, $db_auth;
  46. $con = connect($db_ip, $db_user, $db_password, $db_auth);
  47. if (check_user_exist($username) > 0) {
  48. echo "<font color='#ff0000;'>Username is taken. </font>";
  49. $con->close();
  50. return;
  51. }
  52.  
  53.  
  54. if (check_user_exist($username) == 0) {
  55. if ($stmt = $con->prepare($sql)) {
  56. $stmt->bind_param("ss", $username, $new_password);
  57. $stmt->execute();
  58. $stmt->close();
  59. echo "<script type='text/javascript'>window.location.href = '?success=$username';</script>";
  60. $con->close();
  61. }
  62. }
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement