Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
Add example usage to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehodgkiss committed Sep 28, 2012
1 parent adc3310 commit babd8a8
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
# zxcvbn-ruby

Ruby port of Dropboxs zxcvbn.js
Ruby port of [zxcvbn.js](https://github.com/dropbox/zxcvbn)

## Usage

Gemfile:

```ruby
gem "zxcvbn-ruby", :require => 'zxcvbn'
```

Example user model:

```ruby
class User < Struct.new(:username, :password)
include Zxcvbn

def password_strength
zxcvbn(password, [username])
end
end

>> User.new('alfred', '@lfred2004').password_strength
# => #<Zxcvbn::Score:0x007fafd0c779a0 @entropy=7.895, @crack_time=0.012, @crack_time_display="instant", @score=0, @match_sequence=[#<Zxcvbn::Match matched_word="alfred", token="@lfred", i=0, j=5, rank=1, pattern="dictionary", dictionary_name="user_inputs", l33t=true, sub={"@"=>"a"}, sub_display="@ -> a", base_entropy=0.0, uppercase_entropy=0.0, l33t_entropy=1, entropy=1.0>, #<Zxcvbn::Match i=6, j=9, token="2004", pattern="year", entropy=6.894817763307944>], @password="@lfred2004", @calc_time=0.003048>

>> User.new('alfred', 'asdfghju7654rewq').password_strength
# => #<Zxcvbn::Score:0x007fcf3b563558 @entropy=29.782, @crack_time=46159.451, @crack_time_display="14 hours", @score=2, @match_sequence=[#<Zxcvbn::Match pattern="spatial", i=0, j=15, token="asdfghju7654rewq", graph="qwerty", turns=5, shifted_count=0, entropy=29.7820508329166>], @password="asdfghju7654rewq", @calc_time=0.005015>
```

0 comments on commit babd8a8

Please sign in to comment.