|
8 months ago | |
---|---|---|
.github/workflows | 8 months ago | |
test | 1 year ago | |
.gitignore | 6 years ago | |
CHANGELOG.md | 1 year ago | |
LICENSE | 8 months ago | |
Makefile | 1 year ago | |
README.md | 8 months ago | |
bcrypt.l | 8 months ago | |
build.sh | 6 years ago | |
module.l | 8 months ago | |
test.l | 1 year ago |
This library can be used to hash strings (ex: passwords) using bcrypt in PicoLisp.
v3.1.9+
v20.6.29
, see test runsThese FFI bindings require the bcrypt C library, compiled as a shared library.
make
to pull and compile the bcrypt C Library.bcrypt.l
in your projectOnce compiled, the shared library is symlinked as:
.lib/libbcrypt.so -> .modules/bcrypt/HEAD/libbcrypt.so
The bcrypt.l
file searches for .lib/libbcrypt.so
, relative to its current directory.
To keep everything updated, type:
git pull && make clean && make
Only the following functions are exported publicly:
Factor
Number: a Number between 4 and 31, defaults to 12
otherwisePasswd
String: the String to be hashedSalt
String or Number (optional): a hash String or Number used as a cost Factor (will generate a salt automatically if a Number is provided)NIL
or T
.
Passwd
String: the password StringHash
String: the hashed String of the passwordcar
and seconds in cdr
Note: These functions are not namespace local symbols, which means they would redefine symbols with the same name in the
'pico
namespace.
12
.'InternalError
message will be thrown if there's an error.pil +
(load "bcrypt.l")
(gensalt)
-> "$2a$12$mQn1fUDeEZFW74KD5kU6g."
(gensalt 14)
-> "$2a$14$kjOSmjZeLsBdru7NRPEmQu"
pil +
(load "bcrypt.l")
(hashpw "changeme")
-> "$2a$12$mmxN/qk8yvfjCx./KXtgfuqnUFsXjYv1ZTZmkMtdQ94rTDngiXpsq"
(hashpw "changeme" 14)
-> "$2a$14$gZLc8eII8kCbXgFp2rUcv.PPr/oPioojVy0yP0HMU6z2La.v4pEnG"
(hashpw "changeme" "$2a$14$kjOSmjZeLsBdru7NRPEmQu")
-> "$2a$14$kjOSmjZeLsBdru7NRPEmQuL5eU5YN4Yb48bD1A0Pxzwu/3G/7kwBy"
pil +
(load "bcrypt.l")
(compare "changeme" "$2a$14$kjOSmjZeLsBdru7NRPEmQuL5eU5YN4Yb48bD1A0Pxzwu/3G/7kwBy")
-> T
(compare "changeme" "$2a$12$2Lgk0P5s5VsxDUM2aa/HFu/6DwHce1lbUwJ1kTm092DwEeDRHHYBy")
-> NIL
(catch 'InternalError (compare "changeme" "I have no idea what i'm doing"))
-> (BcryptError . "Unable to hash password")
pil +
(load "bcrypt.l")
(timing)
-> (12 . 0)
(timing 15)
-> (15 . 4)
This library now comes with full unit tests. To run the tests, type:
make check
If you find any bugs or issues, please create an issue.
If you want to improve this library, please make a pull-request.
Copyright (c) 2015-2020 Alexander Williams, Unscramble license@unscramble.jp