Guest User

Untitled

a guest
Nov 23rd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. <?php
  2. session_start(); // for security purposes.
  3.  
  4. /*
  5. Define a character length
  6. -- This is for the username
  7. -- This should not be left blank
  8.  
  9. */
  10.  
  11. define('USERNAME_LENGTH', 50); // 50 Characters
  12.  
  13. /*
  14. Define a character length
  15. -- This is for the Password
  16. -- This should not be left blank
  17.  
  18. */
  19.  
  20. define('PASSWORD_LENGTH', 20); // More than 20 characters long
  21.  
  22. /*
  23. Define PASSWORD Regex.
  24. This can be altered depending on the level of security
  25. */
  26.  
  27. define('PASSWORD_REGEX', '#[A-Z]+#');
  28.  
  29. /*
  30. Define PASSWORD Regex.
  31. */
  32.  
  33. include('Connect.php');
  34.  
  35. class User {
  36.  
  37. protected $username;
  38. protected $password;
  39. protected $email;
  40. protected $contactNum = array();
  41. protected $error = array();
  42.  
  43. public function __construct()
  44. {
  45. if(!defined('ERRORS'))
  46. exit("You have not defined the error management");
  47.  
  48. if(!class_exists("Connect"))
  49. exit("You have not defined the class: Connect");
  50.  
  51. $conn = $conn = new Connect();
  52.  
  53. /*
  54. VALIDATE ALL OF THE USERS DETAILS
  55. NOTE: If you do not want to validate
  56. certain details..
  57.  
  58. */
  59.  
  60. $this->username = $this->_validateUsername($theUsername);
  61. $this->password = $this->_validatePassword($thePassword);
  62. $this->email = $this->_validateEmail($theEmail);
  63. $this->contactNum = $this->_validateContact($theContactNum);
  64.  
  65. }
  66.  
  67. public function _validateUsername($theUsername)
  68. {
  69. if(empty($theUsername))
  70. {
  71. $this->error[] = 'Please enter your email address';
  72. return 0;
  73. }
  74.  
  75. // Check that username length
  76. if(strlen($theUsername) > USERNAME_LENGTH)
  77. {
  78. $this->error[] = 'Username is too long';
  79. return 0;
  80. }
  81.  
  82. if(!preg_match('/^[a-zA-Z0-9_-]{3,16}$/', $theUsername))
  83. $this->error[] = 'Username is not valid';
  84.  
  85. return strip_tags($theUsername);
  86.  
  87. }
  88.  
  89. public function _validatePassword($thePassword)
  90. {
  91. if(empty($thePassword))
  92. {
  93. $this->error[] = 'Please enter your password';
  94. return 0;
  95. }
  96.  
  97. if(strlen($thePassword) > PASSWORD_LENGTH)
  98. {
  99. $this->error[] = 'Your password is too short!';
  100. return 0;
  101. }
  102.  
  103. if(preg_match(PASSWORD_REGEX, $thePassword))
  104. {
  105. $this->error[] = 'Your password is invalid.';
  106. return 0;
  107. }
  108.  
  109. return strip_tags($thePassword);
  110. }
  111.  
  112. public function _validateEmail($theEmail)
  113. {
  114.  
  115. if(!eregi('^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$', $theEmail))
  116. {
  117. $this->error[] = 'Invalid Email Address';
  118. return 0;
  119. }
  120.  
  121. return strip_tags($theEmail);
  122. }
  123.  
  124. public function _validateContact($theContactNum)
  125. {
  126. }
  127.  
  128. public function _checkErrors()
  129. {
  130. if(!empty($this->error))
  131. {
  132. return true;
  133. }else{
  134. return false;
  135. }
  136. }
  137.  
  138. public function _getErrors()
  139. {
  140. return $this->error;
  141. }
  142.  
  143. };
  144.  
  145.  
  146.  
  147. ?>
Add Comment
Please, Sign In to add comment