Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start(); // for security purposes.
- /*
- Define a character length
- -- This is for the username
- -- This should not be left blank
- */
- define('USERNAME_LENGTH', 50); // 50 Characters
- /*
- Define a character length
- -- This is for the Password
- -- This should not be left blank
- */
- define('PASSWORD_LENGTH', 20); // More than 20 characters long
- /*
- Define PASSWORD Regex.
- This can be altered depending on the level of security
- */
- define('PASSWORD_REGEX', '#[A-Z]+#');
- /*
- Define PASSWORD Regex.
- */
- include('Connect.php');
- class User {
- protected $username;
- protected $password;
- protected $email;
- protected $contactNum = array();
- protected $error = array();
- public function __construct()
- {
- if(!defined('ERRORS'))
- exit("You have not defined the error management");
- if(!class_exists("Connect"))
- exit("You have not defined the class: Connect");
- $conn = $conn = new Connect();
- /*
- VALIDATE ALL OF THE USERS DETAILS
- NOTE: If you do not want to validate
- certain details..
- */
- $this->username = $this->_validateUsername($theUsername);
- $this->password = $this->_validatePassword($thePassword);
- $this->email = $this->_validateEmail($theEmail);
- $this->contactNum = $this->_validateContact($theContactNum);
- }
- public function _validateUsername($theUsername)
- {
- if(empty($theUsername))
- {
- $this->error[] = 'Please enter your email address';
- return 0;
- }
- // Check that username length
- if(strlen($theUsername) > USERNAME_LENGTH)
- {
- $this->error[] = 'Username is too long';
- return 0;
- }
- if(!preg_match('/^[a-zA-Z0-9_-]{3,16}$/', $theUsername))
- $this->error[] = 'Username is not valid';
- return strip_tags($theUsername);
- }
- public function _validatePassword($thePassword)
- {
- if(empty($thePassword))
- {
- $this->error[] = 'Please enter your password';
- return 0;
- }
- if(strlen($thePassword) > PASSWORD_LENGTH)
- {
- $this->error[] = 'Your password is too short!';
- return 0;
- }
- if(preg_match(PASSWORD_REGEX, $thePassword))
- {
- $this->error[] = 'Your password is invalid.';
- return 0;
- }
- return strip_tags($thePassword);
- }
- public function _validateEmail($theEmail)
- {
- if(!eregi('^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$', $theEmail))
- {
- $this->error[] = 'Invalid Email Address';
- return 0;
- }
- return strip_tags($theEmail);
- }
- public function _validateContact($theContactNum)
- {
- }
- public function _checkErrors()
- {
- if(!empty($this->error))
- {
- return true;
- }else{
- return false;
- }
- }
- public function _getErrors()
- {
- return $this->error;
- }
- };
- ?>
Add Comment
Please, Sign In to add comment