Class: Lafcadio::PasswordField

Inherits:
TextField show all
Defined in:
lib/lafcadio/objectField/PasswordField.rb

Overview

A PasswordField is simply a TextField that is expected to contain a password value. It can be set to auto-generate a password at random.

Instance Attribute Summary collapse

Attributes inherited from TextField

#large, #size

Attributes inherited from ObjectField

#dbFieldName, #default, #defaultFieldName, #hideDisplay, #hideLabel, #name, #notNull, #notUniqueMsg, #objectType, #unique, #writeOnce

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TextField

#valueForSQL

Methods inherited from ObjectField

#<=>, #bind_write?, #dbWillAutomaticallyWrite, #db_table_and_field_name, #englishName, #firstTime, instantiateFromXml, instantiateWithParameters, instantiationParameters, #nameForSQL, #nullErrorMsg, #prevValue, #processBeforeVerify, #valueForSQL, #valueFromSQL, valueType, #verify, #verifyUniqueness

Constructor Details

#initialize(objectType, maxLength, name = "password", englishName = nil) ⇒ PasswordField

objectType

The domain class that this object field belongs to.

name

The name of this field.

maxLength

The maximum length of the password. (Deprecated)

englishName

The descriptive English name of this field. (Deprecated)



23
24
25
26
27
# File 'lib/lafcadio/objectField/PasswordField.rb', line 23

def initialize(objectType, maxLength, name = "password", englishName = nil)
	super(objectType, name, englishName)
	@maxLength = maxLength
	@autoGenerate = true
end

Instance Attribute Details

#autoGenerateObject

Returns the value of attribute autoGenerate.



17
18
19
# File 'lib/lafcadio/objectField/PasswordField.rb', line 17

def autoGenerate
  @autoGenerate
end

#maxLengthObject (readonly)

Returns the value of attribute maxLength.



16
17
18
# File 'lib/lafcadio/objectField/PasswordField.rb', line 16

def maxLength
  @maxLength
end

Class Method Details

.randomPasswordObject

Returns a random 8-letter alphanumeric password.



8
9
10
11
12
13
14
# File 'lib/lafcadio/objectField/PasswordField.rb', line 8

def PasswordField.randomPassword
	chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".
			split(//)
	value = ""
	0.upto(8) { |i| value += chars[rand(chars.size)] }
	value
end