List

Try: ca/tecreations/ViewFile.php


<?php
class QA extends MySQL {
    
    public function __construct($host = "localhost") {
        global $DB_USER, $DB_PASS, $DB_NAME;
        parent::__construct($host,$DB_USER,$DB_PASS,$DB_NAME);
        $this->setDebug(false);
    }
    
    function hash($text) {
        $hash = password_hash($text, PASSWORD_DEFAULT,array('cost' => 16));
        return $hash;
    }

    function setQ1($uid = "", $qid = "") {
        global $USERS;
        $this->issue("UPDATE $USERS SET q1id='$qid' WHERE uid='$uid'");
    }

    function setQ2($uid = "", $qid = "") {
        global $USERS;
        $this->issue("UPDATE $USERS SET q2id='$qid' WHERE uid='$uid'");
    }
    
    function setQ3($uid = "", $qid = "") {
        global $USERS;
        $this->issue("UPDATE $USERS SET q3id='$qid' WHERE uid='$uid'");
    }
    
    function setA1($uid = "", $a1 = "") {
        global $USERS;
        $this->issue("UPDATE $USERS SET a1='" . $this->hash($a1) ."' WHERE uid='$uid'");
    }
    
    function setA2($uid = "", $a2 = "") {
        global $USERS;
        $this->issue("UPDATE $USERS SET a2='" . $this->hash($a2) ."' WHERE uid='$uid'");
    }
    
    function setA3($uid = "", $a3 = "") {
        global $USERS;
        $this->issue("UPDATE $USERS SET a3='" . $this->hash($a3) ."' WHERE uid='$uid'");
    }

    function getQ1($uid = "") {    
        global $USERS, $QUESTIONS;
        $result = $this->select("SELECT q1id FROM $USERS WHERE uid='$uid'");
        if ($result['count'] == 1) {
            $q1id = $result['rows']['q1id'];
            $result = $this->select("SELECT text FROM $QUESTIONS WHERE id='$q1id'");
            if ($result['count'] == 1) {
                if (isset($result['rows']['text'])) return $result['rows']['text'];
            }
        }
        return false;
    }

    function getQ2($uid = "") {    
        global $USERS, $QUESTIONS;
        $result = $this->select("SELECT q2id FROM $USERS WHERE uid='$uid'");
        if ($result['count'] == 1) {
            $q2id = $result['rows']['q2id'];
            $result = $this->select("SELECT text FROM $QUESTIONS WHERE id='$q2id'");
            if ($result['count'] == 1) {
                if (isset($result['rows']['text'])) return $result['rows']['text'];
            }
        }
        return false;
    }

    function getQ3($uid = "") {    
        global $USERS, $QUESTIONS;
        $result = $this->select("SELECT q3id FROM $USERS WHERE uid='$uid'");
        if ($result['count'] == 1) {
            $q3id = $result['rows']['q3id'];
            $result = $this->select("SELECT text FROM $QUESTIONS WHERE id='$q3id'");
            if ($result['count'] == 1) {
                if (isset($result['rows']['text'])) return $result['rows']['text'];
            }
        }
        return false;
    }
    
    function getA1($uid = "") {
        global $USERS;
        $result = $this->select("SELECT a1 FROM $USERS WHERE uid='$uid'");
        if ($result['count'] == 1) {
            return $result['rows']['a1'];
        }
    }
    
    function getA2($uid = "") {
        global $USERS;
        $result = $this->select("SELECT a2 FROM $USERS WHERE uid='$uid'");
        if ($result['count'] == 1) {
            return $result['rows']['a2'];
        }
    }
    
    function getA3($uid = "") {
        global $USERS;
        $result = $this->select("SELECT a3 FROM $USERS WHERE uid='$uid'");
        if ($result['count'] == 1) {
            return $result['rows']['a3'];
        }
    }
    
    function verifyA1($uid = "", $answer = "") {
        if (password_verify($answer,$this->getA1($uid))) {
            return true;
        }
        return false;
    }
    
    function verifyA2($uid = "", $answer = "") {
        if (password_verify($answer,$this->getA2($uid))) {
            return true;
        } 
        return false;
    }

    function verifyA3($uid = "", $answer = "") {
        if (password_verify($answer,$this->getA3($uid))) {
            return true;
        } 
        return false;
    }
    
    function securityComplete($uid = "") {
        $q1 = $this->getQ1();
        $q2 = $this->getQ2();
        $q3 = $this->getQ3();
        $a1 = $this->getA1();
        $a2 = $this->getA2();
        $a3 = $this->getA3();
        if ($q1 == "" && $q2 == "" && $q3 == "" && $a1 == "" && $a2 == "" && $a3 == "") return false;
        return true;
    }
}
$qa = new QA();