Skip to content
/ Passgen Public
forked from cryptice/Passgen

A password generation gem for Ruby and Rails applications.

Notifications You must be signed in to change notification settings

RingRx/Passgen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Passgen

Ruby gem for generating passwords quickly and easily. Although it is suitable for use within Rails it has no Rails dependencies and can be used in non-Rails applications as well.

It can generate passwords including lower case, upper case, digits and symbols and also pronounceable passwords.

Since 1.0.0 you can also analyze the quality of a password, both as a numeric score between 0 and 100 and as a complexity ranking.

Install

gem install passgen

Usage

The usage could not be easier. Just require and call the generate method:

>> require 'rubygems'
>> require 'passgen'
>> Passgen::generate
=> "zLWCeS3xC9"

You check the strength of a password by calling analyze:

>> info = Passgen::analyze("zLWCeS3xC9")
=> #<Passgen::StrengthAnalyzer:0xb728654c @complexity="Strong", @score=78, @errors=[], @password="zLWCeS3xC9">
>> info.score
=> 78
>> info.complexity
=> "Strong"

Examples

>> Passgen::generate
=> "zLWCeS3xC9"
>> Passgen::generate(:length => 20)
=> "6lCcHvkuEW6OuzAtkoAs"
>> Passgen::generate(:symbols => true)
=> "gr)$6bIym1"
>> Passgen::generate(:lowercase => :only)
=> "ysbwuxbcea"
>> Passgen::generate(:number => 3)
=> ["REdOigTkdI", "PQu8DsV9WZ", "qptKLbw8YQ"]
>> Passgen::generate(:seed => 5)
=> "JoV9M2qjiK"
>> Passgen::generate(:seed => 5) # Will generate same password again
=> "JoV9M2qjiK"
>> Passgen::generate(:pronounceable => true) # Pronounceable, mixed case password
=> "ActeodEuRT"
>> Passgen::generate(:pronounceable => true, :lowercase => :only) # Pronounceable lower case
=> "terysolang"
>> Passgen::generate(:pronounceable => true, :uppercase => :only) # Pronounceable upper case
=> "ACTOPECHEI"
>> Passgen::generate(:pronounceable => true, :digits_before => 3) # Pad with digits in front
=> "886uRApLIN"
>> Passgen::generate(:pronounceable => true, :digits_before => 3) # Pad with digits at the end
=> "uRAPLIN886"

Options:

:lowercase => true/false/:only

  • true - Use lowercase letters in the generated password.

  • false - Do not use lowercase letters in the generated password.

  • :only - Only use lowercase letters in the generated password.

:uppercase => true/false/:only

  • true - Use uppercase letters in the generated password.

  • false - Do not use uppercase letters in the generated password.

  • :only - Only use uppercase letters in the generated password.

:digits => true/false/:only

  • true - Use digits in the generated password.

  • false - Do not use digits in the generated password.

  • :only - Only use digits in the generated password.

:symbols => true/false/:only/:list

  • true - Use symbols in the generated password.

  • false - Do not use symbols in the generated password.

  • :only - Only use symbols in the generated password.

  • :list - A string with the symbols to use. Not implemented yet.

:number => integer

Number of passwords to generate. If >1 the result is an Array.

:length => integer/range

The number of characters in the generated passwords. A range results in passwords lengths within the given range.

:seed => integer/:default

Set the srand seed to the given integer prior to generating the passwords.

:pronounceable => true/false

  • true - Generate pronounceable passwords

  • false - No effect

:digits_after => true/number (Only in combination with :pronounceable)

  • Pads the pronounceable password with number digits at the end. Defaults to 2 if true is passed.

:digits_before => true/number (Only in combination with :pronounceable)

  • Pads the pronounceable password with number digits in front. Defaults to 2 if true is passed.

Default values:

:lowercase => true

:uppercase => true

:digits => true

:symbols => false

:pronounceable => Not implemented yet.

:number => 1

:length => 10

:seed => nil

:pronounceable => false

:digits_after => 2 (Only in combination with pronounceable)

:digits_before => 2 (Only in combination with pronounceable)

Copyright and license

Copyright © 2009-2010 Erik Lindblad

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A password generation gem for Ruby and Rails applications.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%