A simple PHP Extension written in Rust to create scrypt password hashes. Supports building on X86-64 and ARM platforms.
cl.exe
compiler. This is usually bundled with Visual Studio.Clone the repository into your project directory.
git clone https://github.com/appwrite/php-scrypt.git && \
cd php-scrypt
Compile the extension
cargo build --release
We strongly recommend using zigbuild as the linker for this project as we found it's the most stable and easy to install alternate linker. we also use the "-C target-feature=crt-static" compiler flags to aid with building on musl as stated here.
The build command for these platforms will look like so:
RUSTFLAGS="-C target-feature=-crt-static" cargo zigbuild --workspace --all-targets --target x86_64-unknown-linux-musl --release
This will produce a .so file similar to a normal build.
Copy the compiled extension from the target
directory into your PHP extension directory.
If you don't know where your PHP extension directory is you can run the following command:
php -i | grep extension_dir
Copy the extension to the directory outputted
cp target/release/libphp-scrypt.so /path/to/extension_dir
Depending on your OS, your extension may end with
.dll
for windows or.dylib
for macOS.
After compiling and moving the extension into the correct directory, you can enable the extension by adding the following line to your php.ini
file:
extension=libphp-scrypt.so
Change .so to .dll for Windows or .dylib for macOS.
Using the scrypt extension is easy, there is only one function in this extension the usage is as follows:
<?php
/**
* @param $password The string you want to hash (required)
* @param $salt The salt you want to use (required)
* @param $cpu_difficulty The CPU difficulty [default=32768]
* @param $memory_difficulty The memory difficulty [default=8]
* @param $parallel_difficulty The parallel difficulty [default=1]
* @param $len The length of the generated hash [default=8]
**/
$hash = \scrypt("password", "salt", 32768, 8, 1, 64);
\var_dump("Your hash is " . $hash);
Bradley Schofield
Matej Bačo
Eldad Fux
All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the contribution guide.
The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php