PHP Classes

File: uploady/logic/authLogic.php

Recommend this page to a friend!
  Classes of Faris AL-Otabi   Uploady PHP Upload File to MySQL   uploady/logic/authLogic.php   Download  
File: uploady/logic/authLogic.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Uploady PHP Upload File to MySQL
Store file upload details in a MySQL database
Author: By
Last change: Simple API to integrate with other applications
Update packages, fix a missing feature, started working on an API, and minor changes.
Date: 4 months ago
Size: 1,231 bytes
 

Contents

Class file image Download
<?php

$page
= "authPage";

$utils = new Uploady\Utils();
$database = new Uploady\Database();
$user = new Uploady\User($database, $utils);
$auth = new Uploady\Auth($database, $utils, $user);

// Check if the user is loggedin
if (!isset($_SESSION['loggedin'])) {
   
$utils->redirect($utils->siteUrl("/logout.php"));
} elseif (isset(
$_SESSION['OTP']) && ($_SESSION['OTP'] == true)) {
   
$utils->redirect($utils->siteUrl("/index.php"));
} else {
   
$_SESSION['OTP'] = false;
}

$uniqueid = $auth->generateDeviceID();

if (
$auth->checkDeviceId($uniqueid) == true) {
   
$user->regenerateSession();
}

$g = new \RobThree\Auth\TwoFactorAuth("Uploady");

if (
$_SERVER["REQUEST_METHOD"] == "POST") {
   
$code = $utils->sanitize($_POST['otp_code']);
   
$secret = $user->getSecret($_SESSION['username']);

    if (
$g->verifyCode($secret, $code)) {
        if (isset(
$_POST['remberme'])) {
            if (!isset(
$_COOKIE['2fa'])) {
               
$utils->createCookie("2fa", true);
               
$utils->createCookie("device_id", $uniqueid);
            }
        }

       
$user->regenerateSession();
    } else {
       
$error = $lang["general"]["two_factor_auth_failed"];
    }
}

$title = $lang["general"]['two_factor_title'];