Permalink
Browse files

Update docs; plan Windows support

  • Loading branch information...
skinkade committed Apr 10, 2016
1 parent 62cfd02 commit 743ad63c4b664ba6e4ef137ef9d076096fd58082
Showing with 23 additions and 84 deletions.
  1. +1 −0 LICENSE
  2. +12 −74 README.md
  3. +10 −10 lib/Crypt/Bcrypt.pm6
View
@@ -1,4 +1,5 @@
Copyright (c) 2014, carlin <cb@viennan.net>
Copyright (c) 2016, Shawn Kinkade
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
View
@@ -1,82 +1,20 @@
# Crypt::Bcrypt #
Bcrypt password hashing in Perl6.
This is an implementation of bcrypt for Perl 6
## Synopsis ##
```
use Crypt::Bcrypt;
## Example ##
# 2^12 rounds by default
my $hash = bcrypt-hash("password");
my $hard-hash = bcrypt-hash("password", :rounds(15));
use Crypt::Bcrypt;
my $salt = Crypt::Bcrypt.gensalt(10);
my $hash = Crypt::Bcrypt.hash("My password", $salt);
my $password_attempt = Crypt::Bcrypt.hash("My password", $hash);
bcrypt-match("password", $hash); # True
bcrypt-match("password1", $hash); # False
```
if (Crypt::Bcrypt.compare("My password", $hash)) {
say 'O frabjous day! Callooh! Callay!'
}
else {
say 'Does not match :-(';
}
## Methods ##
- `gensalt(Int $rounds = 12)`
Generates a salt seeded with random data
The generated salt includes a prefix specifying the number of rounds
that the password will be hashed with when the returned salt is
passed to `hash`
- `hash(Str $password, Int $rounds = 12)`
A convenience method for generating a hash
Automatically generates the salt used by calling `gensalt`
- `hash(Str $password, Str $salt)`
Generates a hash of the password, using the settings from the salt
The salt should be generated using gensalt but can be passed manually
The salt can also be a fully qualified bcrypt hash, this is useful
if you want to compare a string against a known hash
- `compare(Str $password, Str $hash) returns Bool`
Compares a password with a hash
Returns True if the given hash was created with the provided plain text
## Requirements ##
Your system must be capable of compiling the provided libraries
This should work on most Unix variants, however Windows is not currently
supported as the library depends on the existance of /dev/urandom
Confirmed working on rakudo running on the MoarVM
## How to ##
First get your system ready for compiling
If you installed a Perl 6 implementation from source you probably already
meet this requirement
### Panda ###
This module can be installed using panda:
panda install Crypt::Bcrypt
Alternatively, you can clone the respository using git. After that, if you have
Panda installed, you can build the library by running `panda-build`.
You can then run the tests using `panda-test` and install using `panda-install`.
Once installed the module can be used like any other module, or you can
manually run the tests just like any other Perl 6 code:
perl6 t/01-basic.t
## Contact ##
carlin in #perl6 on Freenode
## Windows ##
Windows support is absent, though planned.
## Credit ##
View
@@ -23,15 +23,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
=end LICENSE
sub library returns Str {
state Str $path;
unless $path {
if $*DISTRO.is-win {
$path = 'blib\lib\crypt_blowfish.dll';
} else {
$path = 'blib/lib/crypt_blowfish.so';
}
}
$path;
state Str $path;
# unless $path {
# if $*DISTRO.is-win {
# $path = 'blib\lib\crypt_blowfish.dll';
# } else {
$path = 'blib/lib/crypt_blowfish.so';
# }
# }
$path;
}
@@ -52,7 +52,7 @@ sub gensalt(int $rounds where 4..31) returns Str {
sub bcrypt-hash(Str $password, int $rounds = 12) returns Str is export {
sub bcrypt-hash(Str $password, int :$rounds = 12) returns Str is export {
crypt($password, gensalt($rounds));
}

0 comments on commit 743ad63

Please sign in to comment.