Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* This Class is the basic user model */
- class User {
- // Constants
- const NICKNAME_MAXLENGTH = 20;
- const NICKNAME_MINLENGTH = 3;
- const PASSWORD_MAXLENGTH = 30;
- const PASSWORD_MINLENGTH = 5;
- // Atributes
- private $user_id;
- private $nickname;
- private $password;
- public function __construct($nickname, $password) {
- $this->nickname = $nickname;
- $this->password = $password;
- }
- public function GetNickname() {
- return $this->nickname;
- }
- public function GetPassword() {
- return $this->password;
- }
- public function VerifyLogins($login, $password) { // Verify the format of the login/password
- $errors = '';
- // We start by verifying the nickname
- if(!preg_match("#^[^(\^\\/*\+\-)]{".self::NICKNAME_MINLENGTH.",".self::NICKNAME_MAXLENGTH."}$#", $login))
- {
- $errors .= 'The nickname is incorrect.<br />';
- }
- // We verify the password
- if(!preg_match("#^[.]{".self::PASSWORD_MINLENGTH.",".self::PASSWORD_MAXLENGTH."}$#", $password))
- {
- $errors .= 'The password is incorrect.<br />';
- }
- // Now if the $errors variable is not empty then there is an error
- if($errors == '')
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public function AddUser($login, $password) { // Add a new user to the database
- global $PA; // To access the PDO variable
- // First we need to verify the logins
- if($this->VerifyLogins($login, $password))
- {
- // Now that we are sure about the validity of the logins, we can add the user to the dabase
- $PA->prepare('INSERT INTO ') or die($PA->error);
- $PA->execute();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement