Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2. /* This Class is the basic user model */
  3. class User {
  4.      // Constants
  5.      const NICKNAME_MAXLENGTH = 20;
  6.      const NICKNAME_MINLENGTH = 3;
  7.      const PASSWORD_MAXLENGTH = 30;
  8.      const PASSWORD_MINLENGTH = 5;
  9.      // Atributes
  10.      private $user_id;
  11.      private $nickname;
  12.      private $password;
  13.      
  14.      public function __construct($nickname, $password) {
  15.          $this->nickname = $nickname;
  16.          $this->password = $password;
  17.      }
  18.      
  19.      public function GetNickname() {
  20.          return $this->nickname;
  21.      }
  22.      
  23.      public function GetPassword() {
  24.          return $this->password;
  25.      }
  26.      
  27.      public function VerifyLogins($login, $password) { // Verify the format of the login/password
  28.          $errors = '';
  29.          // We start by verifying the nickname
  30.          if(!preg_match("#^[^(\^\\/*\+\-)]{".self::NICKNAME_MINLENGTH.",".self::NICKNAME_MAXLENGTH."}$#", $login))
  31.          {
  32.              $errors .= 'The nickname is incorrect.<br />';
  33.          }
  34.          // We verify the password
  35.          if(!preg_match("#^[.]{".self::PASSWORD_MINLENGTH.",".self::PASSWORD_MAXLENGTH."}$#", $password))
  36.          {
  37.              $errors .= 'The password is incorrect.<br />';
  38.          }
  39.          // Now if the $errors variable is not empty then there is an error
  40.          if($errors == '')
  41.          {
  42.              return false;
  43.          }
  44.          else
  45.          {
  46.              return true;
  47.          }
  48.      }
  49.      
  50.      public function AddUser($login, $password) { // Add a new user to the database
  51.          global $PA; // To access the PDO variable
  52.          // First we need to verify the logins
  53.          if($this->VerifyLogins($login, $password))
  54.          {
  55.              // Now that we are sure about the validity of the logins, we can add the user to the dabase
  56.              $PA->prepare('INSERT INTO ') or die($PA->error);
  57.              $PA->execute();
  58.          }
  59.      }
  60. }
  61. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement