forked from smarkets/erlang-bcrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbcrypt.erl
29 lines (22 loc) · 961 Bytes
/
bcrypt.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
%% Copyright (c) 2011 Hunter Morris
%% Distributed under the MIT license; see LICENSE for details.
-module(bcrypt).
-author('Hunter Morris <[email protected]>').
%% API
-export([start/0, stop/0]).
-export([mechanism/0]).
-export([gen_salt/0, gen_salt/1, hashpw/2]).
start() -> application:start(bcrypt).
stop() -> application:stop(bcrypt).
mechanism() ->
{ok, M} = application:get_env(bcrypt, mechanism),
M.
gen_salt() -> do_gen_salt(mechanism()).
gen_salt(Rounds) -> do_gen_salt(mechanism(), Rounds).
hashpw(Password, Salt) -> do_hashpw(mechanism(), Password, Salt).
do_gen_salt(nif) -> bcrypt_nif_worker:gen_salt();
do_gen_salt(port) -> bcrypt_pool:gen_salt().
do_gen_salt(nif, Rounds) -> bcrypt_nif_worker:gen_salt(Rounds);
do_gen_salt(port, Rounds) -> bcrypt_pool:gen_salt(Rounds).
do_hashpw(nif, Password, Salt) -> bcrypt_nif_worker:hashpw(Password, Salt);
do_hashpw(port, Password, Salt) -> bcrypt_pool:hashpw(Password, Salt).