Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Config{
- public static $dbhost = "localhost";
- public static $dbuser = "root";
- public static $dbpass = "";
- public static $dbdata = "Skyhigh";
- }
- global $con;
- $con = new mysqli(Config::$dbhost, Config::$dbuser, Config::$dbpass, Config::$dbdata);
- if($con->connect_errno)
- {
- printf("Connect failed: %s\n", $con->connect_error);
- die("ERROR");
- }
- $action = $_GET['action'];
- class User{
- private $con;
- private $username;
- private $password;
- private $newpassword;
- public function __construct($user, $pass, $newpass) {
- $username = $user;
- $password = $pass;
- $newpassword = $newpass;
- }
- public function exists(){
- $result = $con->query("SELECT ID FROM users WHERE username = " . $username);
- if ($result->num_rows == 0 )
- {
- return 1;
- } else if($result->num_rows == 1)
- {
- return 0;
- } else
- {
- return -1;
- }
- }
- public function login()
- {
- $result = $con->query("SELECT passhash FROM users WHERE username = " . $username);
- while($row = $result->fetch_object()){
- $hash =$row->passhash;
- }
- if (password_verify($password, $hash))
- {
- return 1;
- }else
- {
- return 0;
- }
- }
- public function register()
- {
- if(($password == $newpassword))
- {
- $hash = password_hash($password, PASSWORD_DEFAULT);
- }
- if($query = $con->query("INSERT INTO users (username,passhash) VALUES ('$username','$hash')"))
- {
- echo "1";
- }
- else
- {
- echo "0";
- }
- }
- }
- $name = $con->real_escape_string($_GET['username']);
- $pass1 = $con->real_escape_string($_GET['password']);
- $pass2 = $con->real_escape_string($_GET['newpassword']);
- $user = new User($username, $pass1, $pass2);
- switch ($action)
- {
- case "register":
- if (!$user->exists())
- echo $user->register();
- break;
- case "login":
- if($user->exists())
- echo $user->login();
- break;
- default:
- echo "Please enter an action.";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement