class TfaTestTotp in Two-factor Authentication (TFA) 7.2
Class TfaTestTotp.
Hierarchy
- class \TfaBasePlugin
- class \TfaTestTotp implements TfaValidationPluginInterface
Expanded class hierarchy of TfaTestTotp
1 string reference to 'TfaTestTotp'
- tfa_test_tfa_api in tests/
tfa_test.module - Implements hook_tfa_api().
File
- tests/
includes/ tfa_test.totp.inc, line 11 - Tests for the TfaValidationPluginInterface.
View source
class TfaTestTotp extends TfaBasePlugin implements TfaValidationPluginInterface {
/**
* Data store for testing encryption.
*
* @var string
*/
protected $store;
/**
* {@inheritdoc}
*/
public function ready() {
return variable_get('tfa_test_is_ready', TRUE);
}
/**
* {@inheritdoc}
*/
public function getForm(array $form, array &$form_state) {
$form['code'] = array(
'#type' => 'textfield',
'#title' => t('TOTP code'),
'#required' => TRUE,
);
$form['login'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array $form, array &$form_state) {
$this->code = variable_get('tfa_totp', 123456);
if (!parent::validate($form_state['values']['code'])) {
$this->errorMessages['code'] = t('Invalid TOTP code');
return FALSE;
}
else {
return TRUE;
}
}
/**
* One-off methods that allow for testing base plugin encryption.
*/
public function setInStore($data) {
$this->encryptionKey = drupal_random_bytes(32);
$this->store = $this
->encrypt($data);
}
/**
* One-off methods that allow for testing base plugin encryption.
*/
public function readFromStore() {
return $this
->decrypt($this->store);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TfaBasePlugin:: |
protected | property | TFA code. | |
TfaBasePlugin:: |
protected | property | Code Length. | |
TfaBasePlugin:: |
protected | property | Context of current TFA process. | |
TfaBasePlugin:: |
protected | property | Encryption key. | |
TfaBasePlugin:: |
protected | property | Error messages. | |
TfaBasePlugin:: |
protected | property | Code is valid. | |
TfaBasePlugin:: |
constant | |||
TfaBasePlugin:: |
protected | function | Decrypt a encrypted string. | |
TfaBasePlugin:: |
protected | function | Decrypt using the deprecated Mcrypt extension. | |
TfaBasePlugin:: |
protected | function | Use OpenSSL to decrypt data that was originally encrypted with Mcrypt. | |
TfaBasePlugin:: |
protected | function | Encrypt a plaintext string. | |
TfaBasePlugin:: |
protected | function | Encrypt using the deprecated Mcrypt extension. | |
TfaBasePlugin:: |
protected | function | Generate a random string of characters of length $this->codeLength. | |
TfaBasePlugin:: |
public | function | Get error messages suitable for form_set_error(). | |
TfaBasePlugin:: |
public | function | Submit form. | 1 |
TfaBasePlugin:: |
private | function | A timing safe equals comparison. | |
TfaBasePlugin:: |
protected | function | Validate code. | |
TfaBasePlugin:: |
public | function | Plugin constructor. | 3 |
TfaTestTotp:: |
protected | property | Data store for testing encryption. | |
TfaTestTotp:: |
public | function |
Get TFA process form from plugin. Overrides TfaValidationPluginInterface:: |
|
TfaTestTotp:: |
public | function | One-off methods that allow for testing base plugin encryption. | |
TfaTestTotp:: |
public | function |
Determine if the plugin can run for the current TFA context. Overrides TfaBasePlugin:: |
|
TfaTestTotp:: |
public | function | One-off methods that allow for testing base plugin encryption. | |
TfaTestTotp:: |
public | function |
Validate form. Overrides TfaValidationPluginInterface:: |