Guest User

RegisterClass.txt

a guest
Jun 21st, 2017
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <?php
  2. class RegisterClass
  3. {
  4. private $username;
  5. private $password;
  6. private $email;
  7.  
  8.  
  9. public function getUsername(){
  10. return $this->username;
  11. }
  12.  
  13. public function setUsername($username){
  14. $this->username = $username;
  15. }
  16.  
  17. public function getPassword(){
  18. return $this->password;
  19. }
  20.  
  21. public function setPassword($password){
  22. $this->password = $password;
  23. }
  24.  
  25. public function getEmail(){
  26. return $this->email;
  27. }
  28.  
  29. public function setEmail($email){
  30. $this->email = $email;
  31. }
  32.  
  33. /*public function checkPwLength($password){
  34. if(strlen($password)<6){
  35. return false;
  36. }
  37. else{
  38. return true;
  39. }
  40. }
  41.  
  42. public function checkIfEmpty($username, $password, $email){
  43. if(empty($username && $password && $email)){
  44. return false;
  45. }
  46. else{
  47. return true;
  48. }
  49. }
  50.  
  51. public function checkIfPwsAreEqual($password1, $password2){
  52. if(!$password1 == $password2){
  53. return false;
  54. }
  55. else{
  56. return true;
  57. }
  58. }*/
  59.  
  60. public function checkIfUsernameExists($username, $DB_con){
  61. $count = 0;
  62.  
  63. $sql = "SELECT username FROM user WHERE username = :username";
  64.  
  65. $statement = $DB_con->prepare($sql);
  66.  
  67. $statement->execute(array(':username' => $username));
  68. while($row = $statement->fetch()) {
  69. $count++;
  70. }
  71.  
  72. if($count>0){
  73. return false;
  74. }
  75. else{
  76. return true;
  77. }
  78. }
  79.  
  80. public function checkIfEmailExists($email, $DB_con){
  81. $count = 0;
  82.  
  83. $sql = "SELECT email FROM user WHERE email = :email";
  84.  
  85. $statement = $DB_con->prepare($sql);
  86.  
  87. $statement->execute(array(':email' => $email));
  88. while($row = $statement->fetch()) {
  89. $count++;
  90. }
  91. if($count>0){
  92. return false;
  93. }
  94. else{
  95. return true;
  96. }
  97. }
  98.  
  99. public function insertUser($username, $password, $email, $DB_con){
  100.  
  101. $sql = "INSERT INTO user (username, password, email) VALUES (:username, :password, :email)";
  102.  
  103. $statement = $DB_con->prepare($sql);
  104.  
  105. $statement->bindValue(':username', $username);
  106. $statement->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
  107. $statement->bindValue(':email', $email);
  108.  
  109. if($statement->execute()){
  110. return true;
  111. }
  112. else{
  113. return false;
  114. }
  115.  
  116. }
  117.  
  118.  
  119.  
  120.  
  121. }
  122.  
  123.  
  124. ?>
Add Comment
Please, Sign In to add comment