Guest User

Untitled

a guest
May 12th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <?php
  2. include_once('connect.php');
  3.  
  4. class Register {
  5.  
  6. public $username;
  7. public $password;
  8. public $repeatpass;
  9. public $email;
  10. public $firstname;
  11. public $lastname;
  12. public $date;
  13. public $registerchecks;
  14.  
  15. function __construct() {
  16. $this->username = $_POST['username'];
  17. $this->password = $_POST['password'];
  18. $this->repeatpass = $_POST['repeatpass'];
  19. $this->email = $_POST['email'];
  20. $this->firstname = $_POST['firstname'];
  21. $this->lastname = $_POST['lastname'];
  22. $this->date = date('Y-m-d');
  23. }
  24.  
  25. public function RegisterUser() {
  26.  
  27. $username_check = "SELECT username FROM accounts WHERE username='$this->username'";
  28. $run_username_check = mysql_query($username_check);
  29. $username_check_num_rows = mysql_num_rows($run_username_check);
  30.  
  31. $email_check = "SELECT email FROM accounts WHERE email='$this->email'";
  32. $run_email_check = mysql_query($email_check);
  33. $email_check_num_rows = mysql_num_rows($run_email_check);
  34.  
  35. if (strlen($this->username)>25) {
  36. die ("Username too Long, must be less than 26 characters!");
  37. } else if (!preg_match('#[0-9]#', $this->password)) {
  38. die ("Password must have at least one number!");
  39. } else if ($username_check_num_rows>=1) {
  40. die ("Username already taken!");
  41. } else if ($email_check_num_rows>=1) {
  42. die ("Email already in use!");
  43. } else if (strlen($this->password)<6) {
  44. die ("Password is too short, must be at least 6 characters!");
  45. } else if ($this->password!=$this->repeatpass) {
  46. die ("Passwords did not match!");
  47. } else {
  48. $md5pass = md5($this->password);
  49. $insert = "INSERT INTO accounts VALUES('','$this->username','$md5pass','$this->email','$this->date','$this->firstname','$this->lastname','')";
  50. $run_insert = mysql_query($insert);
  51. if (!$run_insert) {
  52. die ("Something went wrong, please try again :-(");
  53. } else {
  54. echo "Registered Successfully!";
  55. }
  56. }
  57. }
  58. }
  59.  
  60. if(isset($_POST['submit'])) {
  61. $register = new Register();
  62. $register->RegisterUser();
  63. }
  64.  
  65.  
  66. ?>
Add Comment
Please, Sign In to add comment