diff --git a/.gitignore b/.gitignore index d9d343f..4d0dac9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,26 @@ +# The directory Mix will write compiled artifacts to. /_build/ + +# If you run "mix test --cover", coverage assets end up here. /cover/ + +# The directory Mix downloads your dependencies sources to. /deps/ + +# Where third-party dependencies like ExDoc output generated docs. /doc/ -/priv/ + +# Ignore .fetch files in case you like to edit your project deps locally. /.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). *.ez + +# Ignore package tarball (built via "mix hex.build"). +bcrypt_elixir-*.tar + +# Temporary files for e.g. tests +/tmp diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f55446..2781b43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,31 +1,31 @@ # Changelog -## v2.3.0 +## v2.3.0 (2021-01-07) * Enhancements - * updated Makefile to be more robust, especially for Nerves users + * Updated Makefile to be more robust, especially for Nerves users -## v2.2.0 +## v2.2.0 (2020-03-01) * Changes - * using Comeonin v5.3, which changes `add_hash` so that it does NOT set the password to nil + * Using Comeonin v5.3, which changes `add_hash` so that it does NOT set the password to nil -## v2.1.0 +## v2.1.0 (2020-01-20) * Enhancements * Updated documentation - in line with updates to Comeonin v5.2 -## v2.0.0 +## v2.0.0 (2019-02-12) * Enhancements * Updated to use the Comeonin and Comeonin.PasswordHash behaviours (Comeonin v5.0) -## v1.0.0 +## v1.0.0 (2019-01-17) * Enhancements * Updated C NIF code to use dirty schedulers -## v0.12.0 +## v0.12.0 (2017-08-06) * Changes * Created separate Bcrypt library diff --git a/LICENSE b/LICENSE index 4b093c8..d07adf4 100644 --- a/LICENSE +++ b/LICENSE @@ -58,7 +58,7 @@ This password hashing algorithm was designed by David Mazieres All other code in this application, unless otherwise stated, is subject to the following license: -Copyright (c) 2014-2018 David Whitlock +Copyright (c) 2014-2021 David Whitlock Some rights reserved. Redistribution and use in source and binary forms of the software as well diff --git a/README.md b/README.md index bc422f3..8bf41fe 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,11 @@ # Bcrypt -[![Hex.pm Version](http://img.shields.io/hexpm/v/bcrypt_elixir.svg)](https://hex.pm/packages/bcrypt_elixir) [![Build Status](https://travis-ci.com/riverrun/bcrypt_elixir.svg?branch=master)](https://travis-ci.com/riverrun/bcrypt_elixir) +[![Module Version](http://img.shields.io/hexpm/v/bcrypt_elixir.svg)](https://hex.pm/packages/bcrypt_elixir) +[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/bcrypt_elixir/) +[![Total Download](https://img.shields.io/hexpm/dt/bcrypt_elixir.svg)](https://hex.pm/packages/bcrypt_elixir) +[![License](https://img.shields.io/hexpm/l/bcrypt_elixir.svg)](https://github.com/riverrun/bcrypt_elixir/blob/master/LICENSE) +[![Last Updated](https://img.shields.io/github/last-commit/riverrun/bcrypt_elixir.svg)](https://github.com/riverrun/bcrypt_elixir/commits/master) Bcrypt password hashing library for Elixir. @@ -23,72 +27,72 @@ and Comeonin.PasswordHash behaviours. It now has the following two additional convenience functions: * `add_hash/2` - * same as Comeonin.Bcrypt.add_hash in Comeonin version 4 + * same as `Comeonin.Bcrypt.add_hash/2` in Comeonin version 4 * hashes a password and returns a map with the password hash * `check_pass/3` - * same as Comeonin.Bcrypt.check_pass in Comeonin version 4 + * same as `Comeonin.Bcrypt.check_pass/3` in Comeonin version 4 * takes a user struct and password as input and verifies the password ## Installation -1. Add bcrypt_elixir to the `deps` section of your mix.exs file: +1. Add `:bcrypt_elixir` to the `deps` section of your `mix.exs` file: -If you are using Erlang >20: + If you are using Erlang >20: -```elixir -def deps do - [ - {:bcrypt_elixir, "~> 2.0"} - ] -end -``` + ```elixir + def deps do + [ + {:bcrypt_elixir, "~> 2.0"} + ] + end + ``` -If you are using Erlang 19 or below: + If you are using Erlang 19 or below: -```elixir -def deps do - [ - {:bcrypt_elixir, "~> 0.12"} - ] -end -``` + ```elixir + def deps do + [ + {:bcrypt_elixir, "~> 0.12"} + ] + end + ``` -2. Make sure you have a C compiler installed. +2. Make sure you have a C compiler installed. See the [Comeonin wiki](https://github.com/riverrun/comeonin/wiki/Requirements) for details. -3. Optional: during tests (and tests only), you may want to reduce the number of rounds +3. Optional: during tests (and tests only), you may want to reduce the number of rounds so it does not slow down your test suite. If you have a config/test.exs, you should add: -```elixir -config :bcrypt_elixir, :log_rounds, 4 -``` + ```elixir + config :bcrypt_elixir, :log_rounds, 4 + ``` ## Comeonin wiki See the [Comeonin wiki](https://github.com/riverrun/comeonin/wiki) for more information on the following topics: -* [algorithms](https://github.com/riverrun/comeonin/wiki/Choosing-the-password-hashing-algorithm) -* [requirements](https://github.com/riverrun/comeonin/wiki/Requirements) -* [deployment](https://github.com/riverrun/comeonin/wiki/Deployment) - * including information about using Docker -* [references](https://github.com/riverrun/comeonin/wiki/References) +* [Algorithms](https://github.com/riverrun/comeonin/wiki/Choosing-the-password-hashing-algorithm) +* [Requirements](https://github.com/riverrun/comeonin/wiki/Requirements) +* [Deployment](https://github.com/riverrun/comeonin/wiki/Deployment) + * Including information about using Docker +* [References](https://github.com/riverrun/comeonin/wiki/References) ## Contributing There are many ways you can contribute to the development of this library, including: -* reporting issues -* improving documentation -* sharing your experiences with others -* [making a financial contribution](#donations) +* Reporting issues +* Improving documentation +* Sharing your experiences with others +* [Making a financial contribution](#donations) ## Donations First of all, I would like to emphasize that this software is offered free of charge. However, if you find it useful, and you would like to -buy me a cup of coffee, you can do so at [paypal](https://www.paypal.me/alovedalongthe). +buy me a cup of coffee, you can do so at [PayPal](https://www.paypal.me/alovedalongthe). ### Documentation diff --git a/lib/bcrypt.ex b/lib/bcrypt.ex index 4f18b86..d597c5e 100644 --- a/lib/bcrypt.ex +++ b/lib/bcrypt.ex @@ -5,22 +5,21 @@ defmodule Bcrypt do Most applications will just need to use the `add_hash/2` and `check_pass/3` convenience functions in this module. - For a lower-level API, see Bcrypt.Base. + For a lower-level API, see `Bcrypt.Base`. ## Configuration The following parameter can be set in the config file: - * `log_rounds` - the computational cost as number of log rounds - * the default is 12 (2^12 rounds) + * `:log_rounds` - the computational cost as number of log rounds + * the default is `12` (2^12 rounds) If you are hashing passwords in your tests, it can be useful to add the following to the `config/test.exs` file: + # Note: Do not use this value in production config :bcrypt_elixir, log_rounds: 4 - NB. do not use this value in production. - ## Bcrypt Bcrypt is a key derivation function for passwords designed by Niels Provos @@ -54,11 +53,11 @@ defmodule Bcrypt do @doc """ Generate a salt for use with the `Bcrypt.Base.hash_password` function. - The log_rounds parameter determines the computational complexity + The `:log_rounds` parameter determines the computational complexity of the generation of the password hash. Its default is 12, the minimum is 4, and the maximum is 31. - The `legacy` option is for generating salts with the old `$2a$` prefix. + The `:legacy` option is for generating salts with the old `$2a$` prefix. Only use this option if you need to generate hashes that are then checked by older libraries. """ @@ -71,7 +70,7 @@ defmodule Bcrypt do ## Option - * `log_rounds` - the computational cost as number of log rounds + * `:log_rounds` - the computational cost as number of log rounds * the default is 12 (2^12 rounds) * this can be used to override the value set in the config diff --git a/lib/bcrypt/stats.ex b/lib/bcrypt/stats.ex index 3f64fa9..a2fd88a 100644 --- a/lib/bcrypt/stats.ex +++ b/lib/bcrypt/stats.ex @@ -2,12 +2,12 @@ defmodule Bcrypt.Stats do @moduledoc """ Module to provide statistics for the Bcrypt password hashing function. - The `report` function in this module can be used to help you configure + The `report/1` function in this module can be used to help you configure Bcrypt. ## Configuration - There is one configuration option for Bcrypt - log_rounds. + There is one configuration option for Bcrypt - `:log_rounds`. Increasing this value will increase the complexity, and time taken, of the Bcrypt function. @@ -26,7 +26,7 @@ defmodule Bcrypt.Stats do @doc """ Hash a password with Bcrypt and print out a report. - This function hashes a password, and salt, with Bcrypt.Base.hash_password/2 + This function hashes a password, and salt, with `Bcrypt.Base.hash_password/2` and prints out statistics which can help you choose how many to configure Bcrypt. diff --git a/mix.exs b/mix.exs index c2863cf..40ff3f8 100644 --- a/mix.exs +++ b/mix.exs @@ -1,6 +1,7 @@ defmodule BcryptElixir.Mixfile do use Mix.Project + @source_url "https://github.com/riverrun/bcrypt_elixir" @version "2.3.0" @description """ @@ -18,8 +19,9 @@ defmodule BcryptElixir.Mixfile do make_clean: ["clean"], description: @description, package: package(), - source_url: "https://github.com/riverrun/bcrypt_elixir", + source_url: @source_url, deps: deps(), + docs: docs(), dialyzer: [ plt_file: {:no_warn, "priv/plts/dialyzer.plt"} ] @@ -41,12 +43,24 @@ defmodule BcryptElixir.Mixfile do ] end + defp docs do + [ + main: "readme", + source_ref: "v#{@version}", + source_url: @source_url, + extras: ["CHANGELOG.md", "README.md"] + ] + end + defp package do [ files: ["lib", "c_src", "mix.exs", "Makefile*", "README.md", "LICENSE"], maintainers: ["David Whitlock"], licenses: ["BSD"], - links: %{"GitHub" => "https://github.com/riverrun/bcrypt_elixir"} + links: %{ + "Changelog" => "#{@source_url}/blob/master/CHANGELOG.md", + "GitHub" => @source_url + } ] end end