Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8545477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:48:00+00:00 2026-06-11T12:48:00+00:00

I am trying to create a user login system. I have a class/controller called

  • 0

I am trying to create a user login system.

I have a class/controller called AccessControl which includes all the functions for creating, deleting and logging a user in and out.

I also have a model called Users which has all the database functions in it which are called from the AccessControl class.

My AccessControl class:

include_once('../models/User.php') ;

class AccessControl {
private $_systemKey ;

public function __construct()
{
    $this->_systemKey = 'QA>8fg)@z#t#:E60mj&MzHsm-lUj&b-}R%~<y$|nAuF)C3!r%+rT"Q<r$o?{_XR' ;
}

public function createUser($email, $password, $level)
{           
    $user_salt = $this->randomString() ;

    $password = $user_salt . $password ;
    $password = $this->hashData($password) ;

    if(!is_int($level))
    {
        return false ;
    }

    //Create verification code
    $code = $this->randomString() ;

    //SQL...
    $created = User->insertNewUser($email, $password, $level) ;

    if($created != false){
        return true; 
    }

    return false ;
}
}

And in my model:

class User extends Core {

public function fetchSalt($username)
{
    $result = $this->db->prepare("SELECT saltword FROM users WHERE username = ?") ;
    $result->execute(array($username)) ;
    return $result->fetchColumn() ;
}

public function insertNewUser($email, $password, $level)
{
    //SQL Insert...
}

}

I am not sure if I am doing this the right way, because aren’t createUser and insertNewUser identical? How can I change things to make it DRY?


Core is just my PDO connection class, all my models will extend from it. That’s the plan anyway.

abstract class Core {
protected $db ;

function __construct()
{
    try{
        $this->db = new PDO("mysql:host=localhost;dbname=database", "user", "pass") ;
        $this->db->exec('set names utf8') ;
                    $this->db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
        $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
        $this->db->setAttribute(PDO::ATTR_PERSISTENT, TRUE) ;
    }
    catch(PDOEXCEPTION $e)
    {
        echo 'Database error: <i style="color:#993300;">'.$e.'</i>' ;
        die() ;
    }
}

function __destruct()
{
    $this->db = NULL ;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T12:48:02+00:00Added an answer on June 11, 2026 at 12:48 pm

    Generally if you want to keep the code duplication to a minimum in this scenario I would advice you to not have each model handle the database work.

    Instead you can have a gateway for each model that accepts and returns models. Usually for simple retrieval, inserting, removing and updating the queries will not differ much. All the common code can be in an AbstractGateway all the other Gateways extend from. The specific gateways just handle the model specific things then, like defining the table to use or the model to return.

    You also get some added benefits from this. You can easily swap out the database gateway for another storage gateway. That way you can even test your code without having to worry about the database connection.

    As for the create and insert user methods I don’t see a problem there. From an MVC standpoint the createUser method is a method of the Controller and for the action you are performing it calls a method of the Model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple login system that will have the forms and
I am trying to create a login page that will send the user to
I'm trying to create User Control which will work like a rich button. It's
I have created a login system and I am trying to stick to the
I'm trying to manage the login system from spring with a Database, I have
I'm trying to build Facebook OAuth into my existing Authlogic login system. I have
I'm trying to create a user management system using steam openid, but I'm not
I am trying to create a log in system in php. I have 3
I'm trying to create a GUI program, simple LOGIN maintenance. I have 4 gui
I have an Runtime error when I'm trying to perform login action or create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.