app/Containers/User/Models/User.php
/**
     * @param null $username
     * @param int $length
     * @param string $keyspace
     * @return null|string
     * @throws \Exception
     *
     * generates a username that does not collide with other usernames
     *
     */


generates a username that does not collide with other usernames
generates a username that does not collide with other usernames
public function makeUsername($username = null, $length = 6, $keyspace = '0123456789ABCDEFGHIJKLMNOP')
    {
        $field = 'username';
        if ($username) {
            if ($this->collision($field, $username)) {
                $hash = $this->random_str($length, $keyspace);
                if ($this->collision($field, $username.'_'.$hash)) return $this->makeUsername($username);
                else return $username.'_'.$hash;
            }
            else return $username;
        }
        else {
            $hash = $this->random_str($length, $keyspace);
            if ($this->collision($field, $hash)) return $this->makeUsername();
            else return $hash;
        }
    }
public function makeUsername ( $ username = null , $ length = 6 , $ keyspace = '0123456789ABCDEFGHIJKLMNOP' ) { $ field = 'username' ; if ( $ username ) { if ( $ this -> collision ( $ field , $ username ) ) { $ hash = $ this -> random_str ( $ length , $ keyspace ) ; if ( $ this -> collision ( $ field , $ username . '_' . $ hash ) ) return $ this -> makeUsername ( $ username ) ; else return $ username . '_' . $ hash ; } else return $ username ; } else { $ hash = $ this -> random_str ( $ length , $ keyspace ) ; if ( $ this -> collision ( $ field , $ hash ) ) return $ this -> makeUsername ( ) ; else return $ hash ; } }
@param null $username
 @param int $length
 @param string $keyspace
 @return null|string
 @throws \Exception
@param null $username @param int $length @param string $keyspace @return null|string @throws \ Exception