Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class RegisterClass
- {
- private $username;
- private $password;
- private $email;
- public function getUsername(){
- return $this->username;
- }
- public function setUsername($username){
- $this->username = $username;
- }
- public function getPassword(){
- return $this->password;
- }
- public function setPassword($password){
- $this->password = $password;
- }
- public function getEmail(){
- return $this->email;
- }
- public function setEmail($email){
- $this->email = $email;
- }
- /*public function checkPwLength($password){
- if(strlen($password)<6){
- return false;
- }
- else{
- return true;
- }
- }
- public function checkIfEmpty($username, $password, $email){
- if(empty($username && $password && $email)){
- return false;
- }
- else{
- return true;
- }
- }
- public function checkIfPwsAreEqual($password1, $password2){
- if(!$password1 == $password2){
- return false;
- }
- else{
- return true;
- }
- }*/
- public function checkIfUsernameExists($username, $DB_con){
- $count = 0;
- $sql = "SELECT username FROM user WHERE username = :username";
- $statement = $DB_con->prepare($sql);
- $statement->execute(array(':username' => $username));
- while($row = $statement->fetch()) {
- $count++;
- }
- if($count>0){
- return false;
- }
- else{
- return true;
- }
- }
- public function checkIfEmailExists($email, $DB_con){
- $count = 0;
- $sql = "SELECT email FROM user WHERE email = :email";
- $statement = $DB_con->prepare($sql);
- $statement->execute(array(':email' => $email));
- while($row = $statement->fetch()) {
- $count++;
- }
- if($count>0){
- return false;
- }
- else{
- return true;
- }
- }
- public function insertUser($username, $password, $email, $DB_con){
- $sql = "INSERT INTO user (username, password, email) VALUES (:username, :password, :email)";
- $statement = $DB_con->prepare($sql);
- $statement->bindValue(':username', $username);
- $statement->bindValue(':password', password_hash($password, PASSWORD_DEFAULT));
- $statement->bindValue(':email', $email);
- if($statement->execute()){
- return true;
- }
- else{
- return false;
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment