Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Connect to a mysql database
- */
- class mySQL{
- public $host;
- public $username;
- public $password;
- public $database;
- public $dbh;
- public function connect($set_host, $set_username, $set_password, $set_database){
- $this->host = $set_host;
- $this->username = $set_username;
- $this->password = $set_password;
- $this->database = $set_database;
- $this->dbh = mysql_connect($this->host, $this->username, $this->password)or die("cannot connect");
- mysql_select_db($this->database)or die("cannot select DB");
- }
- public function query($sql)
- {
- return mysql_query($sql,$this->dbh);
- }
- public function fetch($sql)
- {
- return mysql_fetch_array($this->query($sql));
- }
- }
- /**
- * loginsystem
- */
- class loginsystem
- {
- public $user;
- public $pass;
- public $pass2;
- public $email;
- public $crypt;
- public $conn;
- public $checkpass;
- public $userinfo;
- public function login($username,$password)
- {
- $this->user = $username;
- $this->pass = $password;
- $db = new mySQL();
- $this->conn = $db->connect('localhost','root','','oop');
- $this->userinfo = $db->fetch("SELECT * FROM users WHERE username = '$this->user'");
- if(!empty($this->user) && !empty($this->pass)){
- $this->checkpass = password_verify($this->pass,$this->userinfo['password']);
- if($this->checkpass) {
- $_SESSION['id'] = $this->userinfo['id'];
- //header('location:user.php');
- echo "succes";
- }else{
- echo "Wrong password or username";
- }
- } else {
- echo "fill in the form";
- }
- }
- function loginform()
- {
- echo " <form action='' method='post'>
- Username:
- <input type='text' name='user' placeholder='Username'>
- Password:
- <input type='password' name='pass' placeholder='Password'>
- <input type='submit' value='Login!' name='send'>
- </form>";
- }
- public function register($username,$password,$password2,$email)
- {
- $db = new mySQL();
- $this->user = $username;
- $this->pass = $password;
- $this->pass2 = $password2;
- $this->email = $email;
- $this->conn = $db->connect('localhost','root','','oop');
- if($this->pass == $this->pass2){
- $this->crypt = password_hash($this->pass, PASSWORD_DEFAULT);
- $db->query("INSERT INTO users VALUES('NULL','$this->user','$this->crypt','$this->email');");
- echo "Succesfull";
- } else {
- echo "Passwords are not the same";
- }
- }
- public function registerform()
- {
- echo ' <form action="" method="post">
- Username:
- <input type="text" name="user" placeholder="Username">
- Password:
- <input type="password" name="pass" placeholder="Password">
- Confirm Password:
- <input type="password" name="pass2" placeholder="Confirm Password">
- E-Mail:
- <input type="text" name="email" placeholder="E-Mail">
- by registering you agree to our TOS wich can be found <a href="tos.html">here</a>
- <input type="submit" value="Register!" name="send">
- </form>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement