https://github.com/appwrite/php-scrypt
https://github.com/appwrite/php-scrypt
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/appwrite/php-scrypt
- Owner: appwrite
- License: mit
- Created: 2022-06-24T14:19:31.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-25T13:53:31.000Z (almost 3 years ago)
- Last Synced: 2025-01-31T18:45:41.905Z (5 months ago)
- Language: Dockerfile
- Size: 190 KB
- Stars: 13
- Watchers: 11
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Scrypt
[](https://appwrite.io/discord)
[](https://twitter.com/appwrite)
[](https://stackshare.io/appwrite)
[](https://appwrite.io)A simple PHP Extension written in Rust to create scrypt password hashes. Supports building on X86-64 and ARM platforms.
## Installation
### Compiling Requirements
- Linux, MacOS or Windows-based operating system
- Latest Version of Rust Stable
- PHP 8.0 or newer
- Clang 5.0 or Later### Notes for Windows compilation
- This extension can only be compiled for PHP installations sourced from https://windows.php.net.
- Rust Nightly is required for Windows compilation.
- This extension requires the `cl.exe` compiler. This is usually bundled with Visual Studio.
- Stub generation does not work on Windows.### Building The Extension
Clone the repository into your project directory.
```bash
git clone https://github.com/appwrite/php-scrypt.git && \
cd php-scrypt
```
Compile the extension
```bash
cargo build --release
```### Building for Alpine
While writing this extension we found out that [Rust in general](https://github.com/rust-lang/rust/issues/59302) still has a few issues with [musl libc](https://musl.libc.org/) found in Alpine. It is possible to build this project successfully by using an alternative linker and building on a gnu-based system targetting `linux-unknown-musl`.
We strongly recommend using [zigbuild](https://github.com/messense/cargo-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](https://github.com/rust-lang/rust/issues/59302).
The build command for these platforms will look like so:
```sh
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.### Installing the Extension
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:
```bash
php -i | grep extension_dir
```Copy the extension to the directory outputted
```bash
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.
### Enabling the extension
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.## Usage
Using the scrypt extension is easy, there is only one function in this extension the usage is as follows:
```php