Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Signup {
- // Properties associated with the user registration form
- protected $username;
- protected $email;
- protected $password;
- protected $missingFields = true;
- // Check to make sure the user entered information in all required form fields
- protected function validate($username, $password, $email)
- {
- try
- {
- if ($_POST && !empty($username) && !empty($password) && !empty($email))
- {
- $this->missingFields = false;
- }
- else
- {
- throw new Exception('Missing Required Fields');
- }
- }
- catch(Exception $e)
- {
- var_dump($e->getMessage());
- }
- }
- public function __construct($username, $password, $email)
- {
- $this->validate($username, $password, $email);
- try
- {
- if($this->missingFields === false)
- {
- $this->username = $username;
- $this->email = $email;
- $this->hashPass($password);
- }
- else
- {
- throw new Exception('Could Not Validate User Fields');
- }
- }
- catch(Exception $e)
- {
- $e->getMessage();
- }
- }
- // Create and store a hash from the user's submitted password
- protected function hashPass($hashedPass)
- {
- $this->password = password_hash($hashedPass, PASSWORD_DEFAULT);
- }
- // Dump the hashed password
- public function showHash()
- {
- try
- {
- if($this->missingFields === false)
- {
- var_dump($this->password);
- }
- else
- {
- throw new Exception('Password could not be hashed');
- }
- }
- catch(Exception $e)
- {
- var_dump($e->getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement