An open API service indexing awesome lists of open source software.

https://github.com/appwrite/php-scrypt


https://github.com/appwrite/php-scrypt

Last synced: 5 months ago
JSON representation

Awesome Lists containing this project

README

        

# PHP Scrypt

[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Follow Appwrite on StackShare](https://img.shields.io/badge/follow%20on-stackshare-blue?style=flat-square)](https://stackshare.io/appwrite)
[![appwrite.io](https://img.shields.io/badge/appwrite-.io-f02e65?style=flat-square)](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