Class: PTJ::Password

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource, Model::FixtureTable
Defined in:
lib/ptj/model/password.rb

Class Method Summary collapse

Methods included from Model::FixtureTable

#fixture_table?

Class Method Details

.classify_passwords(pass) ⇒ Object

Classify an individual password based on the levels of complexities present.

Parameters:

  • pass

    Password to classify.

Returns:

  • Hash :lower => value, :upper => value, :special => value, :number => value



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ptj/model/password.rb', line 55

def self.classify_passwords(pass)
  pass = pass.to_s
  lower = false
  upper = false
  special = false
  number = false

  case pass
  when /^[a-z]+$/
    lower = true
  when /^[^a-zA-Z0-9]+$/
    special = true
  when /^[A-Z]+$/
    upper = true 
  when /^[0-9]+$/
    number = true
  when /^([a-zA-Z]*([a-z]+[A-Z]+|[A-Z]+[a-z]+)[a-zA-Z]*)$/
    lower = upper = true
  when /^([a-z0-9]*([a-z]+[0-9]+|[0-9]+[a-z]+)[a-z0-9]*)$/
    lower = number = true
  when /^(([a-z]|[^a-zA-Z0-9])*([a-z]+[^a-zA-Z0-9]+|[^a-zA-Z0-9]+[a-z]+)([a-z]|[^a-zA-Z0-9])*)$/
    lower = special = true
  when /^([0-9A-Z]*([0-9]+[A-Z]+|[A-Z]+[0-9]+)[0-9A-Z]*)$/
    upper = number = true
  when /^(([A-Z]|[^a-zA-Z0-9])*([A-Z]+[^a-zA-Z0-9]+|[^a-zA-Z0-9]+[A-Z]+)([A-Z]|[^a-zA-Z0-9])*)$/
    upper = special = true
  when /^(([0-9]|[^a-zA-Z0-9])*([0-9]+[^a-zA-Z0-9]+|[^a-zA-Z0-9]+[0-9]+)([0-9]|[^a-zA-Z0-9])*)$/
    number = special = true
  when /^([a-zA-Z0-9]*([a-z]+[A-Z]+[0-9]+|[a-z]+[0-9]+[A-Z]+|[A-Z]+[a-z]+[0-9]+|[A-Z]+[0-9]+[a-z]+|[0-9]+[A-Z]+[a-z]+|[0-9]+[a-z]+[A-Z]+)+[a-zA-Z0-9]*)$/
    lower = upper = number = true
  when /^(([^a-zA-Z0-9]|[A-Z0-9])*([^a-zA-Z0-9]+[A-Z]+[0-9]+|[^a-zA-Z0-9]+[0-9]+[A-Z]+|[A-Z]+[^a-zA-Z0-9]+[0-9]+|[A-Z]+[0-9]+[^a-zA-Z0-9]+|[0-9]+[A-Z]+[^a-zA-Z0-9]+|[0-9]+[^a-zA-Z0-9]+[A-Z]+)+([^a-zA-Z0-9]|[A-Z0-9])*)$/
    upper = number = special = true
  when /^(([^a-zA-Z0-9]|[a-z0-9])*([^a-zA-Z0-9]+[a-z]+[0-9]+|[^a-zA-Z0-9]+[0-9]+[a-z]+|[a-z]+[^a-zA-Z0-9]+[0-9]+|[a-z]+[0-9]+[^a-zA-Z0-9]+|[0-9]+[a-z]+[^a-zA-Z0-9]+|[0-9]+[^a-zA-Z0-9]+[a-z]+)+([^a-zA-Z0-9]|[a-z0-9])*)$/
    lower = number = special = true
  when /^(([^a-zA-Z0-9]|[a-zA-Z])*([^a-zA-Z0-9]+[a-z]+[A-Z]+|[^a-zA-Z0-9]+[A-Z]+[a-z]+|[a-z]+[^a-zA-Z0-9]+[A-Z]+|[a-z]+[A-Z]+[^a-zA-Z0-9]+|[A-Z]+[a-z]+[^a-zA-Z0-9]+|[A-Z]+[^a-zA-Z0-9]+[a-z]+)+([^a-zA-Z0-9]|[a-zA-Z])*)$/
    lower = upper = special = true
  else
    lower = number = special = upper = true unless pass == ""
  end
  
  return {:lower => lower, :upper => upper, :special => special, :number => number}
end