UniFi - Custom Portal With Individual Usernames and Passwords

warning_25x25.png DISCLAIMER: This is an example of a rudimentary, functioning external portal. Ubiquiti does not support this code, and we will not be updating this article further. Our support team will be unable to assist you with anything related to this article. 

If you would like to implement a configuration similar to the one shown here, it is recommended that you test it moving forward to confirm whether it works in newer firmware versions.


Readers will learn how to customize the UniFi portal in order for each guest to login using a unique username and password, checked against a database (e.g., MySQL)

Attached is a very rudimentary custom portal.  It's written in HTML and PHP and was configured on a Ubuntu 12.04 x64 server.  You will need your appropriate web server (Apache2), PHP5, curl packages, and MySQL server packages.

The attachment includes the following files:

  • .htaccess - Specifies the order of which index.* file to use
  • auth.php - This is where the meat of the functionality is.  It cleans up any input and calls a pair of functions that are in the config.php.inc
  • config.php.inc - This is where are the credentials and functions are stored.  The auth_user function is the check against the MySQL database for user existence, password validation, and optionally, email validation.  The sendAuthorization function notifies UniFi to authorize the user IF the user has passed the auth_user function.
  • index.php - The HTML form that prompts for username, password, and email.
  • hotspot.sql - The MySQL structure for simple ID, username, password, and email columns.  Note that the way the structure and the code is written, passwords are stored in the database as plain text.  You can modify to hash the passwords for security reasons if you prefer

There are also comments all over the place to aide someone in figuring out what the code is doing where.  This is obviously a very stripped down front end:

The main pieces are the auth_user and the sendAuthorization functions which are found in config.php.inc  You can build whatever you need to off of those.

If putting this on Ubuntu or Debian (assuming the standard paths):

  1. Install prerequisites (MySQL Server, Apache2, PHP5, curl, php5-curl, etc) 
  2. mkdir -p /var/www/guest/s/default/
  3. cd /var/www/guest/s/default
  4. Download the attached file to this location
  5. Extract the .zip file with `unzip -xvf MySQL\ Custom\ Portal Example.zip` (You may need to install the unzip package)
  6. Import hotspot.sql
  7. Create/grant user privileges on the hotspot database
  8. Modify config.php.inc with the appropriate credentials

The process of installing most of these required packages is outlined on this site.

It's important to note that you cannot include folders in your External Portal option, just an IP address.  You can either modify the default Apache2 index.html file to redirect to the appropriate path, or create a symlink to the guest/s/default/index.php file.

Last, setup UniFi to point to the IP of the portal server.  You can test authentication by inserting a dummy account in to the MySQL database.

Optional: If you're not familiar with MySQL, you may want to download a front-end for it, such as phpmyadmin (apt-get install phpmyadmin <- for Debian based distributions).  This will vastly help when adding/modifying/deleting users.  Alternatively, you can create your own PHP page to modify users.

It's also worth noting that you can expand on this quite a bit.  For example, you could add code to the PHP and columns to MySQL to log authentications, the user's MAC address, time of last authentication, etc.

Disclaimer: Ubiquiti will not support this code.  It is provided simply as an example of a rudimentary, functioning external portal.