{"id":19956097,"url":"https://github.com/krowinski/tinyid","last_synced_at":"2025-05-03T19:32:40.322Z","repository":{"id":33023230,"uuid":"150095347","full_name":"krowinski/tinyID","owner":"krowinski","description":"Shorten and obfuscate IDs","archived":false,"fork":false,"pushed_at":"2024-05-08T09:52:40.000Z","size":18,"stargazers_count":33,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-07T20:56:18.466Z","etag":null,"topics":["composer-packages","database-ids","encoding","hash","id","ids","obfuscate","php","shortid","tinyid"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krowinski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-24T11:55:42.000Z","updated_at":"2024-11-09T02:52:23.000Z","dependencies_parsed_at":"2024-11-18T07:03:55.946Z","dependency_job_id":null,"html_url":"https://github.com/krowinski/tinyID","commit_stats":{"total_commits":11,"total_committers":4,"mean_commits":2.75,"dds":"0.36363636363636365","last_synced_commit":"0d831dc606d4824509832964dee6cbc88e46d152"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krowinski%2FtinyID","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krowinski%2FtinyID/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krowinski%2FtinyID/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krowinski%2FtinyID/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krowinski","download_url":"https://codeload.github.com/krowinski/tinyID/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252242220,"owners_count":21717123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer-packages","database-ids","encoding","hash","id","ids","obfuscate","php","shortid","tinyid"],"created_at":"2024-11-13T01:30:02.623Z","updated_at":"2025-05-03T19:32:40.101Z","avatar_url":"https://github.com/krowinski.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shorten and obfuscate IDs\n\n[![PHP Tests](https://github.com/krowinski/tinyID/actions/workflows/tests.yml/badge.svg)](https://github.com/krowinski/tinyID/actions/workflows/tests.yml)\n[![Latest Stable Version](https://poser.pugx.org/krowinski/tinyid/v/stable)](https://packagist.org/packages/krowinski/tinyid)\n[![Total Downloads](https://poser.pugx.org/krowinski/tinyid/downloads)](https://packagist.org/packages/krowinski/tinyid)\n[![License](https://poser.pugx.org/krowinski/tinyid/license)](https://packagist.org/packages/krowinski/tinyid)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/krowinski/tinyid/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/krowinski/tinyid/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/krowinski/tinyid/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/krowinski/tinyid/?branch=master)\n\n## SYNOPSIS\n\n```php\n    use TinyID\\TinyID;\n    \n    include __DIR__ . '/../vendor/autoload.php';\n    \n    // dictionary must consist of at least two UNIQUE unicode characters.\n    $tinyId = new TinyID('2BjLhRduC6Tb8Q5cEk9oxnFaWUDpOlGAgwYzNre7tI4yqPvXm0KSV1fJs3ZiHM');\n    \n    var_dump($tinyId-\u003eencode('48888851145')); // will print 1FN7Ab\n    var_dump($tinyId-\u003edecode('1FN7Ab')); // will print '48888851145'\n```\n\n## DESCRIPTION\n\nUsing real IDs in various places - such as GET links or API payload - is generally a bad idea:\n\n* It may reveal some sensitive information about your business, such as growth rate or amount of customers.\n* If someone finds unprotected resource link, where you forgot to check if passed resource ID really belongs to currently logged-in user, he will be able to steal all of your data really fast just by\n  incrementing ID in links.\n* Big numbers may cause overflows in places where length is limited, such as SMS messages.\n\nWith the help of this module you can shorten and obfuscate your IDs at the same time.\n\n## METHODS\n\n### new TidyID('qwerty')\n\nKey must consist of at least two ***unique*** unicode characters.\n\nThe longer the dictionary - the shorter encoded ID.\n\nEncoded ID will be made exclusively out of characters from the key. This very useful property allows to adapt your encoding to the environment. For example in SMS messages you may restrict key to US\nASCII to avoid available length reduction caused by conversion to GSM 03.38 charset. Or if you want to use such ID as file/directory name in case-insensitive filesystem you may want to use only\nlowercase letters in the key.\n\n### encode('123')\n\nEncode positive integer into a string.\n\nNote that leading `0`s are not preserved, `encode('123')` is the same as `encode('00123')`.\n\nUsed algorithm is a base to the length of the key conversion that maps to distinct permutation of characters. Do not consider it a strong encryption, but if you have secret and long and well shuffled\nkey it is almost impossible to reverse-engineer real ID.\n\n### decode('rer')\n\nDecode string back into a positive integer.\n\n## TRICKS\n\nIf you provide sequential characters in key you can convert your numbers to some weird numeric systems, for example base18:\n\n```php\n    var_dump((new TinyID('0123456789ABCDEFGH'))-\u003eencode('48888851145')); // '47F709HFF'\n```\n\nOr you can go wild just for the fun of it.\n\n```php\n    var_dump((new TinyID('😀😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏😐😑😒😓😔😕😖😗😘😙😚😛😜😝😞😟😠😡😢😣😤😥😦😧😨😩😪😫😬😭😮😯😰😱😲😳😴😵😶😷😸😹😺😻😼😽😾😿'))-\u003eencode(48888851145)); // '😭😢😀😊😫😉'\n```\n\n## COMPATIBLE COUNTERPARTS\n\n* [Raku](https://github.com/bbkr/TinyID) - `TinyID`\n* [Rust](https://crates.io/crates/squishyid) - `SquishyID`\n* [Perl](http://search.cpan.org/~bbkr/Integer-Tiny-0.3/lib/Integer/Tiny.pm) - `Integer::Tiny`\n\nExamples are in example dir.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrowinski%2Ftinyid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrowinski%2Ftinyid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrowinski%2Ftinyid/lists"}