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.

Install

gem install cryptice-passgen --source http://gems.github.com

Usage

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

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

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(:seed => :default) # Will set random seed...
=> "SI8QDBdV98"
>> Passgen::generate(:seed => :default) # and hence give different password
=> "tHHU5HLBAn"

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.

:pronounceable => true/false

Not implmented 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.

Default values:

:lowercase => true

:uppercase => true

:digits => true

:symbols => false

:pronounceable => Not implemented yet.

:number => 1

:length => 10

:seed => nil

Copyright and license

Copyright © 2009 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.