Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User{
- public $id;
- public $username;
- public $email;
- private $password;
- public $loggedin = false;
- //whatever you require for a login here.
- public function __construct($username,$password){
- $sql = new SimpelSQL(); //plugin I wrote and use to make SQL more simple and faster, otherwise to much code... :)
- $this->username = $username;
- $this->password = $password;
- $this->id = $sql->select("id","users",array("username" => $this->username));
- $this->email = $sql->select("email","users",array("username" => $this->username));
- }
- public function login(){
- $oldpassword = $sql->select("password","users",array("id" => $this->id));
- if(password_verify($this->password,$oldpassword)){
- $this->setSession();
- $this->loggedin = true;
- }
- return $this->loggedin;
- }
- public function create($username,$email,$password){
- if($sql->exists("users",array("username" => $username))){
- $sql->insert("users",array(
- 0,
- $username,
- $email,
- $password
- ));
- return true;
- }
- return false;
- }
- public function setSession(){
- $_SESSION["id"] = $this->id;
- $_SESSION["username"] = $this->username;
- return $_SESSION;
- }
- public function isLoggedIn(){
- return $this->loggedin;
- }
- public function verify_user(){
- if($sql->exists("users",array("username" => $this->username))){
- return true;
- }
- return false;
- }
- public function setPassword($password){
- $this->password = $password;
- return $this;
- }
- public function getPassword($password){
- return $this->password;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement