{"id":18482880,"url":"https://github.com/spaze/encrypt-hash-password-php","last_synced_at":"2025-04-08T18:32:00.430Z","repository":{"id":151090196,"uuid":"21020998","full_name":"spaze/encrypt-hash-password-php","owner":"spaze","description":"Example of an encrypted password hash storage in PHP","archived":false,"fork":false,"pushed_at":"2015-05-12T01:28:33.000Z","size":212,"stargazers_count":21,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-23T16:51:25.356Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spaze.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}},"created_at":"2014-06-20T01:11:58.000Z","updated_at":"2020-12-10T19:07:32.000Z","dependencies_parsed_at":"2023-04-05T09:21:57.559Z","dependency_job_id":null,"html_url":"https://github.com/spaze/encrypt-hash-password-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaze%2Fencrypt-hash-password-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaze%2Fencrypt-hash-password-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaze%2Fencrypt-hash-password-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spaze%2Fencrypt-hash-password-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spaze","download_url":"https://codeload.github.com/spaze/encrypt-hash-password-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247902301,"owners_count":21015426,"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":[],"created_at":"2024-11-06T12:31:36.690Z","updated_at":"2025-04-08T18:31:55.414Z","avatar_url":"https://github.com/spaze.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Hash and encrypt, PHP examples\n==============================\n\nExample of an encrypted password hash storage in PHP, uses bcrypt for hashing and AES-128 in CBC mode for encryption. It uses [defuse/php-encryption](https://github.com/defuse/php-encryption) package for crypto operations.\n**Do not** encrypt just the passwords, encrypt only password hashes for extra security.\n\n## Usage\n\n- Install [defuse/php-encryption](https://github.com/defuse/php-encryption) via [Composer](https://packagist.org/packages/defuse/php-encryption) first, or at least copy the `Crypto.php` file to your project\n- Don't write your own encryption functions\n\n## Key\nGenerate 128-bit key (in PHP hexdec-chars string) using\n\n- `echo preg_replace('/(..)/', '\\x$1', bin2hex(openssl_random_pseudo_bytes(16)));`\n- or by running `openssl rand -hex 16 | sed s/\\\\\\(..\\\\\\)/\\\\\\\\x\\\\1/g` in `bash`\n\nThe key should be stored in the following format: `\"\\xf3\\x49\\xf9\\x4a\\x0a\\xb2 ...\"`. Do NOT encode the `$key` with `bin2hex()` or `base64_encode()` or similar, they may leak the key to the attacker through side channels.\n\n## Files\n\n- [`example-encrypthash.php`](example-encrypthash.php) - Encrypted password hash storage, uses bcrypt + AES-128-CBC with PKCS#7 padding and SHA-256 HMAC authentication using *Encrypt-then-MAC* approach\n- [`example-hash.php`](example-hash.php) - Password hash storage, uses bcrypt.\n- [`functions-encrypthash.php`](functions-encrypthash.php) - Functions used by `example-encrypthash.php`\n- [`tests/encrypthash.php`](tests/encrypthash.php) - Tests for encrypted hash functions\n- [`tests/hash.php`](tests/hash.php) - Tests for hash functions\n\n## Tests\nSimple tests are included, run them with `php tests/hash.php` and `php tests/encrypthash.php`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaze%2Fencrypt-hash-password-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspaze%2Fencrypt-hash-password-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspaze%2Fencrypt-hash-password-php/lists"}