phpass

A simple implementation of PHPass’ Portable Hash.


License
MIT

Documentation

Build Status Hex pm

PHPass

PHPass is an Erlang port of the Portable PHP password hashing framework. Only the md5 hashing method is currently supported.

Setup

For Elixir

Add it to your deps:

defp deps do
  [{:phpass, "0.1.0"}]
end

Ensure that phpass is started with your application, for example by adding it to the list of your application's extra_applications:

def application do
  [
    extra_applications: [:logger, :phpass]
  ]
end

For Erlang

If you're using rebar3, add phpass as a dependency in your project's rebar.config file:

{deps, [
  {phpass, {git, "git://github.com/ostinelli/phpass.git", {tag, "0.1.0"}}}
]}.

Or, if you're using Hex.pm as package manager (with the rebar3_hex plugin):

{deps, [
  {phpass, "0.1.0"}
]}.

Ensure that phpass is started with your application, for example by adding it in your .app file to the list of applications:

{application, my_app, [
    %% ...
    {applications, [
        kernel,
        stdlib,
        sasl,
        phpass,
        %% ...
    ]},
    %% ...
]}.

API

Example code here below is in Erlang. Thanks to Elixir interoperability with Erlang, the equivalent code in Elixir is straightforward.

To hash a password:

phpass:hash(Password) ->
    phpass:hash(Password, 13).
phpass:hash(Password, Rounds) -> Hash.

Types:
    Password = binary()
    Rounds = non_neg_integer()
    Hash = binary()

To check a password:

phpass:check(Password, Hash) -> boolean().

Types:
    Password = binary()
    Hash = binary()

Contributing

So you want to contribute? That's great! Please follow the guidelines below. It will make it easier to get merged in.

Before implementing a new feature, please submit a ticket to discuss what you intend to do. Your feature might already be in the works, or an alternative implementation might have already been discussed.

Do not commit to master in your fork. Provide a clean branch without merge commits. Every pull request should have its own topic branch. In this way, every additional adjustments to the original pull request might be done easily, and squashed with git rebase -i. The updated branch will be visible in the same pull request, so there will be no need to open new pull requests when there are changes to be applied.

Ensure that proper testing is included. To run tests you simply have to be in the project's root directory and run:

$ make test