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

  • SEARCH
  • Home
  • 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 6533599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:08:51+00:00 2026-05-25T10:08:51+00:00

I am trying to build a user-module that can be used in most of

  • 0

I am trying to build a user-module that can be used in most of the web applications I am using zend-framework to build it and so far I have done following work:

User and Access Control Related Tables

user

user_id (int 11 auto increment PK)
username (varchar 50 unique)
password (varchar 25)
email (varchar 50)
created_on (datetime)
updated-on (datetime)
lastvisit (datetime)
status (boolean default 1) 

role

role_id (int 11 auto increment PK)
role_name (varchar 25 unique)
description (varchar 100) 

user_role

user_id (int 11 foreign key to user table)
role_id (int 11 foreign key to role table) 

user_reset

reset_id (int 11 auto increment PK)
user_email (varchar 50)
uniqid(varchar 20)
reset_flag (tinyint 1) 

Controllers and Actions

UserControllers

  • registerAction

user_status is set to zero

  • enableUserAction

enable user uri will be sent via email, user_status to one

  • forgotPasswordAction

  • loginAction

  • resetPasswordAction

  • editInfoAction

  • changePasswordAction

  • accountInfoAction

  • disableAccountAction

  • logoutAction

Models, Logic and DbInteraction Layers

Class UserTable()

Methods

  • save ($data)
  • update ($data, $condition, $value)
  • fetch ($fields, $condition, $value)
  • delete ($condition, $value)
  • getUserById($uid)
  • getUserByEmail($email)

Class User()

  • validation (most of the validation are done using zend library)
    • email validation
    • username validation (duplication, no. of characters)
    • password validation etc…

Methods:

  • user_emailNotification

@params toEmail String

{email settings, email templates, send mail}

  • user_authentication

@params username | emalilAddress String, String

returns Boolean

  • user_checkUniqueEmail

@params email String

returns Boolean

  • user_checkResetFlag

@params email String

returns Boolean

I am trying to make this module as reusable as possible so I would love to recieve any of ur suggestions regarding the class structure, database/table structure or anything regarding the module to make it more modular. So If you have any suggestions do post it.

  • 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-05-25T10:08:52+00:00Added an answer on May 25, 2026 at 10:08 am

    I think your model is fine, the only thing I would change is your USerTable Class and split it into 2 separate classes :

    • A class that manages low-level interaction with the data persistence service (your DB, but it could be a webservice too)
    • a table similar to this one, which manages business rules for login, but which calls the low level class just mentioned (like a delegate) for real data access/persistence.

    With this system, your UserTable doe not need to be rewritten if you change the way you store users data, and each class has only a single responsability.

    But as far as I can guess, you store your passwords in plain text (25 chars are not enough for md5 nor sha*). You should really not do that : in your db, edit your password column to be at least 64 chars long.

    Then use a strong hash with salt for storing passwords (like sha256, here is a sample) :

    <?php
     define('SALT', 'myVery53cr3tpA55w0rd!');
     //I assume the password is already defined
     $pass =  hash('sha256',SALT.$pass);
    

    This is the very minimum. You can perform multiple hash loops on the password to make them stronger, or use some frameworks for managing password security, like phpass.

    that’s a bit off-topic, but there are too many hacked websites’dumps with plaintext passwords out there

    Hope that helps !
    Benjamin

    Edit : Here are some precisions for UserTable separation :

    The main objective is to have a business class that contains the business model and operations, not matter what system is used for storing and fetching the data. This class will use a specific “storage” adapter for each data persistence service.

    This class could look like this :

    <?php
    class UserManager
    {
        private $adapter; 
    
    
    public function __construct($adapter)
    {
        $this->adapter = $adapter; 
    }
    
    public function save($user)
    {
        if ($this->adapter->userExists()) {
            return false;
        }
        try {
            $this->adapter->save($user);
        } catch(Exception $e) {
            //Log or do whatever you want with the exception
            return false;
        }
        return true;
    }
    
    public function deleteUser($user)
    {
        if(!$this->adapter->userExists()) {
            throw new Exception ("User : ".$user->getName()." does not exists");
        }
    }
    
    //add all required operations here (fetching all users, finding a user,...) 
    }
    

    This class performs all necessary operations for managing an user, but it needs an adapter that will be responsible for the real data manipulation, and will depend on the underlying data storage service. Let’s create an interface first, for being able to manage multiple data storage services :

    <?php
    interface UserStorageAdapterInterface
    {
    public function save(User $user);
    public function delete(User $user);
    public function userExists(User $user);
    /** TO be continued **/
    }
    

    This interface allows us to ensure that the adapter will contain the required methods for working with our UserManager, whenever we use a RDBMS, a NoSQL or a webservice for data storage.

    Then, we can implement a specific class for our current RDBMS :

    <?php
    Class UserStorageAdapterPDO implements  UserStorageAdapterInterface
    {
    private $dbAdapter;
    public function __construct($dbAdapter)
    {
        $this->dbAdapter = $sbAdapter;
    }
    
    public function userExists(User $user)
    {
        $sql = "SELECT COUNT * FROM user WHERE user_id = ".(int)$user->getId().";";
        $rs = $dbAdapter->fetchAll($sql);
        if($rs[0]!= 0) {
            return true;
        }
        return false;
    }
    }
    

    We can now implement another class for a Soap webservice :

    <?php
    Class UserStorageAdapterSoap implements  UserStorageAdapterInterface
    {
    private $soapClient;
    public function __construct($soapClient)
    {
        $this->soapClient = $soapClient;
    }
    
    public function userExists(User $user)
    {
        $rs = $this->soapClient->userExists($user);
        if($rs === 1) {
            return true;
        }
        return false;
    }
    }
    

    This architecture adds a small level of complexity, but gives you several benefices :

    • Testability : you just need to mock your adapter in order to test your business rules on user management
    • Separation of concerns : With this architecture, you can update your storage adapter without worrying after your business model, that stays untouched
    • Extensibility : if one of your next apps uses a Nosql db (for instance), it will be easy to create a new storage adapter without extending nor rewriting your Manager class, which could lead to more errors are more code is rewritten.

    IS that more clear for you ? If not, tell me 🙂

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

Sidebar

Related Questions

I'm trying to build a registration module where user can only register if their
I am trying to build a voting system where user can vote without signing
I'm trying to build an array/object based on user-input to a form that has
I'm trying to build a small testing app with erlang+mnesia. I have a user
I am trying (and learning) to build a java web framework, and in the
I'm currently trying to build a simple component which should monitor, if the user
I am trying to build a shopping cart site. When a user click add
I am trying to build a shopping website with ajax. When a user clicks
What I am trying to do is build a form in which the user
I'm trying to have the action of a HTML form built when the user

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.