2007-09-16 02:44:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Abstract base class for a login form
|
|
|
|
*
|
|
|
|
* This class is used as a base class for the different log-in forms like
|
|
|
|
* {@link MemberLoginForm} or {@link OpenIDLoginForm}.
|
|
|
|
*
|
|
|
|
* @author Markus Lanthaler <markus@silverstripe.com>
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-02-25 03:10:37 +01:00
|
|
|
* @subpackage security
|
2007-09-16 02:44:30 +02:00
|
|
|
*/
|
|
|
|
abstract class LoginForm extends Form {
|
2007-10-28 22:44:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Authenticator class to use with this login form
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2007-10-28 22:44:38 +01:00
|
|
|
* Set this variable to the authenticator class to use with this login
|
|
|
|
* form.
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $authenticator_class;
|
|
|
|
|
2017-09-04 18:11:02 +02:00
|
|
|
/**
|
|
|
|
* The minimum amount of time authenticating is allowed to take in milliseconds.
|
|
|
|
*
|
|
|
|
* Protects against timing enumeration attacks
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
private static $min_auth_time = 350;
|
|
|
|
|
2007-10-28 22:44:38 +01:00
|
|
|
/**
|
2014-10-06 05:01:33 +02:00
|
|
|
* Get the authenticator instance
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2014-10-06 05:01:33 +02:00
|
|
|
* @return Authenticator Returns the authenticator instance for this login form.
|
2007-10-28 22:44:38 +01:00
|
|
|
*/
|
|
|
|
public function getAuthenticator() {
|
|
|
|
if(!class_exists($this->authenticator_class) || !is_subclass_of($this->authenticator_class, 'Authenticator')) {
|
2012-09-26 23:34:00 +02:00
|
|
|
user_error("The form uses an invalid authenticator class! '{$this->authenticator_class}'"
|
|
|
|
. " is not a subclass of 'Authenticator'", E_USER_ERROR);
|
2007-10-28 22:44:38 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-10-06 05:01:33 +02:00
|
|
|
return Injector::inst()->get($this->authenticator_class);
|
2007-10-28 22:44:38 +01:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-04-26 13:29:35 +02:00
|
|
|
/**
|
|
|
|
* Get the authenticator name.
|
|
|
|
* @return string The friendly name for use in templates, etc.
|
|
|
|
*/
|
|
|
|
public function getAuthenticatorName() {
|
|
|
|
$authClass = $this->authenticator_class;
|
|
|
|
return $authClass::get_name();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2017-09-12 16:57:03 +02:00
|
|
|
public function setAuthenticatorClass($class)
|
|
|
|
{
|
|
|
|
$this->authenticator_class = $class;
|
|
|
|
$authenticatorField = $this->Fields()->dataFieldByName('AuthenticationMethod');
|
|
|
|
if ($authenticatorField) {
|
|
|
|
$authenticatorField->setValue($class);
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2007-09-16 02:44:30 +02:00
|
|
|
}
|
|
|
|
|