Welcome Guest, Not a member yet? Register   Sign In
Suggestions for designing a app
#7

Personally I'm using UUIDv4 to create unique customer ID's. It's not for security, but so that other customers can't guess how many documents, files, other customers there are in the system. You will still need to implement security measure to ensure that they only have access to their own data.

I'm storing it in BINARY as there are are a performance hit to JOIN table ID's as VARCHAR.

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

if ( ! 
function_exists('UUID_TO_BIN'))
{
    function 
UUID_TO_BIN($uuid) {
        
$uuid hex2bin(str_replace('-','',$uuid));
        return 
$uuid;
    }
}

if ( ! 
function_exists('BIN_TO_UUID'))
{
    function 
BIN_TO_UUID($uuid) {
        if( empty(
$uuid) ) return;
        
$uuid bin2hex($uuid);
        
$uuid substr($uuid08) . '-' substr($uuid84) . '-' substr($uuid124) . '-' substr($uuid164)  '-' substr($uuid20);
        return 
$uuid;
    }
}


if ( ! 
function_exists('UUIDv4'))
{
    
/**
     * Generates a random UUID using the secure RNG.
     *
     * Returns Version 4 UUID format: xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx where x is
     * any random hex digit and Y is a random choice from 8, 9, a, or b.
     *
     * @return string the UUID
     */
    
function UUIDv4()
    {
        
$bytes random_bytes(16);
        
$bytes[6] = chr((ord($bytes[6]) & 0x0f) | 0x40);
        
$bytes[8] = chr((ord($bytes[8]) & 0x3f) | 0x80);
        
$uuid vsprintf('%s%s-%s-%s-%s-%s%s%s'str_split(bin2hex($bytes), 4));
        return 
$uuid;
    }
}

if ( ! 
function_exists('VALID_UUIDv4'))
{
    function 
VALID_UUIDv4($uuid)
    {
        return (bool) 
preg_match('/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i',$uuid);
    }

Reply


Messages In This Thread
Suggestions for designing a app - by rad2 - 09-03-2019, 08:03 PM
RE: Suggestions for designing a app - by rad2 - 09-05-2019, 08:00 AM
RE: Suggestions for designing a app - by jreklund - 09-05-2019, 11:53 AM
RE: Suggestions for designing a app - by InsiteFX - 09-05-2019, 05:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB