Class: Passmakr

Inherits:
Object
  • Object
show all
Defined in:
lib/passmakr.rb

Overview

Class to generate easy to remember passwords, random passwords and urandom passwords, it also has various utilities to crypt and hash passwords in ways compatable with various things like apache htpasswd, /etc/passwd, /etc/shadow and so forth

It include code from www.caliban.org/ruby/ruby-password.shtml

Constant Summary collapse

ONE_DIGIT =

This flag is used in conjunction with Passmakr.phonemic and states that a password must include a digit.

1
ONE_CASE =

This flag is used in conjunction with Passmakr.phonemic and states that a password must include a capital letter.

1 << 1
MD5 =

MD5 algorithm (see crypt(3) for more information)

false
DES =

DES algorithm

true
PASSWD_CHARS =

Characters that may appear in generated passwords. Passmakr.urandom may also use the characters + and /.

'0123456789' +
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
'abcdefghijklmnopqrstuvwxyz'
SALT_CHARS =

Valid salt characters for use by Passmakr#crypt.

'0123456789' +
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
'abcdefghijklmnopqrstuvwxyz' +
'./'
CONSONANT =

phoneme flags

1
VOWEL =
1 << 1
DIPHTHONG =
1 << 2
NOT_FIRST =

indicates that a given phoneme may not occur first

1 << 3
PHONEMES =
{
    :a      => VOWEL,
    :ae     => VOWEL      | DIPHTHONG,
    :ah     => VOWEL      | DIPHTHONG,
    :ai     => VOWEL      | DIPHTHONG,
    :b      => CONSONANT,
    :c      => CONSONANT,
    :ch     => CONSONANT  | DIPHTHONG,
    :d      => CONSONANT,
    :e      => VOWEL,
    :ee     => VOWEL      | DIPHTHONG,
    :ei     => VOWEL      | DIPHTHONG,
    :f      => CONSONANT,
    :g      => CONSONANT,
    :gh     => CONSONANT  | DIPHTHONG | NOT_FIRST,
    :h      => CONSONANT,
    :i      => VOWEL,
    :ie     => VOWEL      | DIPHTHONG,
    :j      => CONSONANT,
    :k      => CONSONANT,
    :l      => CONSONANT,
    :m      => CONSONANT,
    :n      => CONSONANT,
    :ng     => CONSONANT  | DIPHTHONG | NOT_FIRST,
    :o      => VOWEL,
    :oh     => VOWEL      | DIPHTHONG,
    :oo     => VOWEL      | DIPHTHONG,
    :p      => CONSONANT,
    :ph     => CONSONANT  | DIPHTHONG,
    :qu     => CONSONANT  | DIPHTHONG,
    :r      => CONSONANT,
    :s      => CONSONANT,
    :sh     => CONSONANT  | DIPHTHONG,
    :t      => CONSONANT,
    :th     => CONSONANT  | DIPHTHONG,
    :u      => VOWEL,
    :v      => CONSONANT,
    :w      => CONSONANT,
    :x      => CONSONANT,
    :y      => CONSONANT,
    :z      => CONSONANT
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mode = :phonemic, length = 8) ⇒ Passmakr

Creates a password instance, possible modes are:

  • :phonemic - produces easily remembered passwords

  • :random - uses the ruby random function to generate a password

  • :urandom - uses linux /dev/urandom to generate a password

  • anything else will be used as the password instead of generating one

Each instance will have a unique hash of password information in the password attribute, the hash will have members:

  • :string - the actual password string

  • :crypt - a crypt encoded version with a salt, usable in unix password hashes

  • :md5 - a md5 hash usable in unix password hashes

  • :nato - a NATO alphabet readable version of the password

  • :rot13 - for kicks, a ro13 encoded version of the password



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/passmakr.rb', line 103

def initialize(mode=:phonemic, length=8)
    pw = nil

    case mode
        when :urandom
            pw = urandom(length)
        when :random
            pw = random(length)
        when :phonemic
            pw = phonemic(length)
        else
            pw = mode
    end

    preppw(pw)
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



7
8
9
# File 'lib/passmakr.rb', line 7

def password
  @password
end