I am writing an ERM application using the Zend Framework in which user accounts are created under a main company account, enabling me to limit the number of user accounts for a company based on the license which the company paid for. Each company account has its own database (with identical structure to other companies) on my server to store data relevant to that company. The name of each companies database is stored in my "back end" database along with the rest of the companies account information and license key. The authentication system works as follows:
- A new user (having never used the application before) lands on the index page and is greeted by a single text field for "Company Account Number"
- After clicking "Submit", the next step in authentication is for username and password. When the user submits this form, all three pieces of information (account number, user name and password) are sent to my application's Authentication handler.
- My "back end" database which stores company accounts is first queried to see if the account entered by the user exists. If it does, the
company_db_name
column is returned and a connection established then saved in theZend_Registry
. Otherwise, authentication has failed. - If the company account does exist, the database that was returned then has its
users
table queried for the specified username and password hash which either returns a successful instance ofMyApp_Auth
orfalse
if the credentials were incorrect.
At first, I planned on storing user session data in the individual companies database, however I have run into the problem that there is no connection to this database when first landing on the application's index page. I have planned a workaround as follows:
- Move my session storage table out of the customer's database to my "backend" database, which has a connection as soon as the application launches.
- Add a "company account number" column to the table and index this column.
- When a user lands on the application
index
page, the backend database can then be queried for the current user agent'ssessionid
. If it is found, then return all the necessary information i.e. the company database name to establish a connection, and the user's information to build a model with.
I have a couple questions regarding this approach:
Question 1 : Is there any risk in storing all session information for every user of my application in a single back-end database table? I am thinking in the multi-thousand user mindset.
Question 2 : I am concerned that a new user may visit the index page and by complete chance (understanding that this is a very low possibility, but still possible) have the same session_id as an existing session in the back-end database. Is this a valid concern, and if so, can it be mitigated?
Question 3 : Is there a better way, or would you recommend a different method to achieve my required functionality?
Thank you for your time!